Блог пользователя allllekssssa

Автор allllekssssa, история, 7 лет назад, По-английски

Hi,

I was doing previous div 1 round and I got WA on the second task ( 33rd testcase). I wasn't able to understand why I got Wrong Answer, so I asked question on contest blog and had a few answers. They were very helpful, but still I do not understand whole sotry about my mistake and some different outputs of my program ( all programs looks same for me ).

  1. Contest submission 25046285

  2. First submission after contest 25087377 (only added getchar(), immediately after cin )

  3. Second submission after contest 25087412 (I changed place of getchar(), and wrote it one line above)

I understood why I needed to add one extra getline(), but I do not understand why getchar() is needed and why second and third submissions gives different verdicts.

I will be grateful for any help :)

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится -15 Проголосовать: не нравится

Klasican papak...

»
7 лет назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

I see no getchar() in the 2 submission. It is needed to remove the '\n' character that is left in the buffer after you read n and m.

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится +16 Проголосовать: не нравится

You need getchar() or getline() right after first cin to skip new line (\n char) after the first input line, so, getline in next cycle will read from the second input line. Verdicts for your 2 and 3 solutions have a difference because of cycle conditions difference before line if (sz[i]==3).