thatznikhil's blog

By thatznikhil, 11 years ago, In English

208A - Dubstep

I am getting right answer for the given test cases for this problem but don't know why on submitting the solution, for the same(i.e. first) test case, the judge says:

Checker comment

wrong answer 1st words differ - expected: 'ABC', found: 'ABC'

This is my submission of the solution: 4452060

Any help regarding this is highly appreciated.

  • Vote: I like it
  • +6
  • Vote: I do not like it

| Write comment?
»
11 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I think that your output contains '\n' in the end. But in checker comment it is ignored. May be this '\n' not needed in output

»
11 years ago, # |
  Vote: I like it 0 Vote: I do not like it

There is an extra space in your output, and i think the checker is space sensitive (it never used to be), look for extra trailing spaces.

  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I also doubted the same, so \b to remove that trailing space, if any present at end.

    See this submission: 4452358

    Even then getting WA.

    See if you can help me out.

    • »
      »
      »
      11 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      cout << '\b' does not erase the last written character. Rather than that, it writes the byte whose value corresponds to the character \b to the output. In ASCII it is character 8.

      It is the terminal software/hardware (on the receiving end, not on the sending end) which recognizes these special characters and then does something accordingly. But if you write data to a file instead of a terminal, the characters will remain as written.

      • »
        »
        »
        »
        11 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks for the info!

        So do you mean i can't erase the last written character anyhow??

        • »
          »
          »
          »
          »
          11 years ago, # ^ |
          Rev. 2   Vote: I like it +3 Vote: I do not like it

          Correct, once a character has been written, there is no way to cancel this.

          You can either output characters more carefully, or write them all into a string, then change the string as you like and finally output the modified string.

          P.S. The problem is not the trailing space. You should fix the problem that PavelKunyavskiy pointed out.

          • »
            »
            »
            »
            »
            »
            11 years ago, # ^ |
            Rev. 2   Vote: I like it +3 Vote: I do not like it

            Thanks andreyv... finally my solution got accepted!!

            Actually what i was doing was trying to print the character (supposedly)stored at an index that was greater than the size of the string and it was printing the NULL (whose ASCII code is 0) as a result.

            (got this idea from PavelKunyavskiy's comment below!)

»
11 years ago, # |
  Vote: I like it +6 Vote: I do not like it

If output (int)a[i] instead of a[i] you can see, that you outputs four characters with codes 65 66 67 0.

  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You are absolutely correct.

    So, going by your suggestion i used "\b " after the 'for loop'. Now when i use (int)a[i], it outputs three characters(i.e. A B C) with codes 65 66 67.

    See this submission: 4452358

    BUT EVEN THEN the judge declares it as a wrong answer with the same checker comment as before: wrong answer 1st words differ - expected: 'ABC', found: 'ABC'

    Please correct me where i might be wrong.

    • »
      »
      »
      11 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      judge checks your output just as biary file. So \b probably shouldn't work. Anyway i don't now whar is it.