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

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

The problem is http://mirror.codeforces.com/gym/100519/problem/I.

The problem request you to guess a prime P, P is less than or equals to N, and N is the first line in a test case.

Your program should make some guesses and the judge will return a answer string when your program do that. It confused me on the I/O.

Here are my two different codes:

while (cin >> n) {
    do {
        cout << my guess number << endl;
        cin >> ans;                  // ans is answer string
        do something.
    } while (it should keep going);
    if (ans[0] == 'O')               // means the answer string is "OK"
        continue;
    get the P.
    cout << P << endl;
    cin >> ans;                      // it will always return "OK" when you guess is current
}
while (scanf("%d", &n) != EOF) {
    do {
        printf("%d\n", my guess number);
        scanf("%s", ans);            // ans is answer string
        do something.
    } while (it should keep going); 
    if (ans[0] == 'O')               // means the answer string is "OK"
        continue;
    get the P.
    printf("%d\n", P);
    scanf("%s", ans);                // it will always return "OK" when you guess is current
}

The first one get Ac, and the second one get "Idleness limit exceeded".

Could anyone help me?

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

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

Well I'm not sure about that but I think most interactive problems require flushing the output after each thing you print, so the judge's program can get access to it. This is done by fflush(stdout); for example.

My guess is that the first program works, since cout<<endl; automatically flushes the output, while printf doesn't.