写这篇文章主要是记录自己犯的第二个错误----标志变量乱赋值(本人小白,欢迎大佬批评指正)
如上为找bug拿OJ测试的记录:(以后看到这篇文章会被自己蠢死!)
如下为我不成熟的、不简洁的代码:
#include<stdio.h>
#define N 10000
int main()
{
int n, m, i, j, k, a[N], sum1, sum2 = 0, sum[N];
scanf("%d", &n);
int flag, count = 0;
int t = 0, t1[N] = { 0 }, e = 0;
for(i = 1; i <= n; i++)
{
sum1 = 0;
flag = 1;
scanf("%d", &m);
for(j = 1; j <= m; j++)
{
scanf("%d", &a[j]);
if(a[j] < 0)
{
sum1 += a[j];
}
if(a[j] > 0 && a[j] != a[1] + sum1)
{
flag = j;
sum1 = 0;
t1[i] = 1; //之前50分卡半天,因为这儿写的是(t1[i]++)
}
}
sum[i] = sum1 + a[flag];
}
for(k = 1; k <= n; k++)
{
sum2 += sum[k];
}
for(k = 1; k <= n; k++)
{
t += t1[k];
if(t1[k] == 1)
count++;
if(t1[k] == 0)
count = 0;
if(count >= 3)
e++;
}
if(t1[1] == 1 && t1[2] == 1 && t1[n] == 1)
e++;
if(t1[n - 1] == 1 && t1[n] == 1 && t1[1] == 1)
e++;
printf("%d %d %d", sum2, t, e);
}