|
|
вернуться в форумПоказать все сообщения Спрятать все сообщенияProgram gives the correct answers. But I getting WA1. What is wrong? #include <stdio.h> int main () { int n, y, count; char x;
for (scanf ("%d", &n); n > 0; --n) { fflush (stdin); scanf ("%c%1d", &x, &y); count = 0;
if (x + 2 <= 'h' && y + 1 <= 8) ++count; if (x + 1 <= 'h' && y + 2 <= 8) ++count; if (x - 2 >= 'a' && y + 1 <= 8) ++count; if (x - 1 >= 'a' && y + 2 <= 8) ++count; if (x + 2 <= 'h' && y - 1 >= 1) ++count; if (x + 1 <= 'h' && y - 2 >= 1) ++count; if (x - 2 >= 'a' && y - 1 >= 1) ++count; if (x - 1 >= 'a' && y - 2 >= 1) ++count;
printf ("%d\n", count); } } I've just tested it on test in statement and get this answer: 2 2 2 How it's possible? I'm using Microsoft Visual C++ 2010, and get absolutely right answers. Look at the code. How can get the answer 2 2 2? I don't know why, but scanf sometimes read char and string wrong.I've got thet's problem, change scanf on cin and have AC.Please explain somebody why. |
|
|