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

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

Hello CodeForces. I wrote this code for today's problem A and it got AC. I want to know how this got AC with big mistake in input:

    scanf("%lld", &n);
    cin >> s;

However, input should be only line contains string. Why scanf is ignored? This works locally on my computer you can check in your pc.

Thanks in advance.

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

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

Q and A are not digits and you are not checking result of scanf.

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

It ain't a mystery. Scanf does not find a match for specified format %lld. If you look at the return value of this line, you'll see it's 0 — number of matches found. If there's no match, no variable will be assigned. Nothing bad happens and it's totally expectable.

So, scanf is not ignored, but assignment is ignored, because no matches for %lld were found.