Задача 09. Kamino Factory от Arrays - Exercise - 10/100 в judge
Добър вечер (отново ), колеги,
Някой би ли бил така добър да ми помогне да си открия грашката в кода, защото буквално от сутринта се мъча с тази задача? Какви ли не проверки направих и не иска, и не иска да сработи в judge :( Примерните входове работят.
Условие:
9.*Kamino Factory
The clone factory in Kamino got another order to clone troops. But this time you are tasked to find the best DNA sequence to use in the production.
You will receive the DNA length and until you receive the command "Clone them!" you will be receiving a DNA sequences of ones and zeroes, split by "!" (one or several).
You should select the sequence with the longest subsequence of ones. If there are several sequences with same length of subsequence of ones, print the one with the leftmost starting index, if there are several sequences with same length and starting index, select the sequence with the greater sum of its elements.
After you receive the last command "Clone them!" you should print the collected information in the following format:
"Best DNA sample {bestSequenceIndex} with sum: {bestSequenceSum}."
"{DNA sequence, joined by space}"
Input / Constraints
- The first line holds the length of the sequences – integer in range [1…100];
- On the next lines until you receive "Clone them!" you will be receiving sequences (at least one) of ones and zeroes, split by "!" (one or several).
Output
The output should be printed on the console and consists of two lines in the following format:
"Best DNA sample {bestSequenceIndex} with sum: {bestSequenceSum}."
"{DNA sequence, joined by space}"
Examples
Input |
Output |
Comments |
5 1!0!1!1!0 0!1!1!0!0 Clone them! |
Best DNA sample 2 with sum: 2. 0 1 1 0 0 |
We receive 2 sequences with same length of subsequence of ones, but the second is printed, because its subsequence starts at index[1]. |
Input |
Output |
Comments |
4 1!1!0!1 1!0!0!1 1!1!0!0 Clone them! |
Best DNA sample 1 with sum: 3. 1 1 0 1 |
We receive 3 sequences. Both 1 and 3 have same length of subsequence of ones -> 2, and both start from index[0], but the first is printed, because its sum is greater. |
А при този вход какъв трябва да е индексът? Защо да не е 3?
Олееееее, чак сега загрях, че bestSequenceIndex е РЕДЪТ, а не индексът на най-добрата ДНК Успях да докарам 100/100, и то в 73 реда код - https://pastebin.com/j3jp3Lnv