why my code is wrong? i'm just curious where the logic went wrong it failed at test case:6 Your text to link here... Please help me ASAP
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
why my code is wrong? i'm just curious where the logic went wrong it failed at test case:6 Your text to link here... Please help me ASAP
Name |
---|
You fail to consider the case where there's more than one of the same character. For example, in the test case "www", your program says "chat with her", but the answer should be "ignore him". After count-=1, you should do "if (count>0) count=1;"
1) When i is equal to j, n (the j-th character) will always be equal to
c[i]
. Try starting yourfor
at i = j + 1.2) You need to break out of the
for
loop whenn == c[i]
is true, in order to not count repeating characters multiple times.3) Because you are already subtracting
c.Length
fromcount
(character by character when doingcount = count-1
),count
after the for loop is exactly the number of distinct characters, but with a minus sign. There are two ways to fix the calculation of k, the number of distinct characters: Either delete thecount = count-1
line (and keepk = c.Length - count
, becausecount
would then represent the number of repeated letters) or usek = -count
.I submitted your solution with the proposed changes here.
Thanks for the help I understood it crisp and clear Can you add me as a friend?