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

Автор PoustouFlan, история, 21 месяц назад, По-английски

Hello, codeforces!

As I am currently learning C in my computer science classes, I was thinking about trying to solve fundamental 800-1000 problems in C in codeforces.

But... I have no idea why this is happening :

#include <stdio.h>

int main()
{
    size_t n;
    scanf("%zu", &n);
    printf("%zu", n);
}

As a custom invocation, if you give 1 as input, it gives you 2 as output. It gave me random values in other contexts. It seems to behave fine when I use "%ld" instead of "%zu".

Any idea why this happens?

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

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

Auto comment: topic has been updated by PoustouFlan (previous revision, new revision, compare).

»
21 месяц назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Quick search shows that Windows might be the problem. At least, it explains why you experience this problem in CF.

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

Auto comment: topic has been updated by PoustouFlan (previous revision, new revision, compare).

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

Looking at the scanf documentation, it seems like the %z specifier was introduced by C99, and I think codeforces use C11.

C11 is for the most part a superset of C99.

  • »
    »
    21 месяц назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Oh wow I thought it was the opposite, I just realized it refered to the year two lasts digits ~

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

Auto comment: topic has been updated by PoustouFlan (previous revision, new revision, compare).