12640 - Largest Sum Game
Time limit: 1.000 seconds
题目:http://uva.onlinejudge.org/external/126/12640.pdf
主要是读取数据怎么处理。
完整代码:
/*0.055s*/
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
char ch;
int x, maxn, sum, exit;
while (true)
{
maxn = sum = 0;
while (true)
{
exit = scanf("%d%c", &x, &ch);
if (exit == -1) return 0;
sum += x;
if (sum <= 0) sum = 0;
else maxn = max(maxn, sum);
if (ch == '\n' || exit == 1)
{
printf("%d\n", maxn);
break;
}
}
}
return 0;
}