一个acm题目,老是WA,不知道哪个边界没考虑!求大神!!!
题目:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1003代码:#include<stdio.h>#include<...
题目:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1003
代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int T=0,
i=0,
j=0; //循环
int grade=0,
leave=0,
day=0,
a=1; //连续次数
scanf("%d",&T);
for(i=1;i<=T;i++)
{//循环1
scanf("%d",&day);
int *p;
p=(int *)malloc(day *sizeof(int));
for(j=0;j<day;j++)
{scanf("%1d",&p[j]);}
for(j=0;j<day;j++)
{//循环2
if(p[j]==1)
{
grade=grade+a*10;
a++;
if(a>5)
{a=1;}
}
else if(p[j]==0)
{
a=1;
}
} // 循环2
leave=(grade>=750?8:(grade/50+1)/2);
printf("%d",leave);
free(p);
grade=0;
}//循环1
return 0;
} 展开
代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int T=0,
i=0,
j=0; //循环
int grade=0,
leave=0,
day=0,
a=1; //连续次数
scanf("%d",&T);
for(i=1;i<=T;i++)
{//循环1
scanf("%d",&day);
int *p;
p=(int *)malloc(day *sizeof(int));
for(j=0;j<day;j++)
{scanf("%1d",&p[j]);}
for(j=0;j<day;j++)
{//循环2
if(p[j]==1)
{
grade=grade+a*10;
a++;
if(a>5)
{a=1;}
}
else if(p[j]==0)
{
a=1;
}
} // 循环2
leave=(grade>=750?8:(grade/50+1)/2);
printf("%d",leave);
free(p);
grade=0;
}//循环1
return 0;
} 展开
1个回答
展开全部
#include<stdio.h>
#include<stdlib.h>
int main()
{
int T = 0,
i = 0,
j = 0;
int grade = 0,
leave = 0,
day = 0,
a = 1;
scanf("%d", &T);
for (i = 1; i <= T; i++)
{
scanf("%d", &day);
int *p;
p = (int *)malloc(day *sizeof(int));
for (j = 0; j < day; j++)
{
scanf("%1d", &p[j]);
}
for (j = 0; j < day; j++)
{
if (p[j] == 1)
{
grade = grade + a * 10;
a++;
if (a>5)
{
a = 1;
}
}
else if (p[j] == 0)
{
a = 1;
}
}
leave = (grade >= 750 ? 8 : (grade / 50 + 1) / 2);
// \n 需要一个换行
printf("%d\n", leave);
free(p);
grade = 0;
a = 1; // 这里需要重置a = 1
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询