该题的数据是在 Windows 下造的,换行符为 \r\n。
因此你快读的时候要判 \r 而不只有 \n。
这是一份可以过的代码:
#include <stdio.h>
int main() {
char ch;
int n = 0;
while ((ch = getchar_unlocked()) != '\r') {
n *= 10;
n += ch - '0';
}
getchar_unlocked();
int ans = 0;
int x = 0;
int t = 1;
for (int i = 1; i < n; i++) {
x = 0;
ch = getchar_unlocked();
if (ch == '-')
t = -1;
else {
t = 1;
x = ch - '0';
}
while ((ch = getchar_unlocked()) != ' ') {
x *= 10;
x += ch - '0';
}
ans += x * t;
}
x = 0;
ch = getchar_unlocked();
if (ch == '-')
t = -1;
else {
t = 1;
x = ch - '0';
}
while ((ch = getchar_unlocked()) != '\r') {
x *= 10;
x += ch - '0';
}
ans += x * t;
printf("%d", ans);
return 0;
}
这是一份全 TLE 的代码:
#include <stdio.h>
int main() {
char ch;
int n = 0;
while ((ch = getchar()) != '\n') {
n *= 10;
n += ch - '0';
}
int ans = 0;
int x = 0;
int t = 1;
for (int i = 1; i < n; i++) {
x = 0;
ch = getchar();
if (ch == '-')
t = -1;
else {
t = 1;
x = ch - '0';
}
while ((ch = getchar()) != ' ') {
x *= 10;
x += ch - '0';
}
ans += x * t;
}
x = 0;
ch = getchar();
if (ch == '-')
t = -1;
else {
t = 1;
x = ch - '0';
}
while ((ch = getchar()) != '\n') {
x *= 10;
x += ch - '0';
}
ans += x * t;
printf("%d", ans);
return 0;
}
请求更正数据 @Little09