杭电acm1004的问题,为什么老是答案错误呢???
这是我的代码题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004#include<stdio.h>#include<st...
这是我的代码
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004
#include<stdio.h>
#include<string.h>
int main()
{
int n,max,i;
int b[5]={0,0,0,0,0};
char a[1001];
char c[15][15]={"green","red","blue","pink","orange"};
while(scanf("%d",&n)!=EOF,n!=0)
{ if(!(n>0&&n<=1000))
continue;
max=0;
getchar();
while(n--)
{
gets(a);
switch(a[0])
{
case 103: b[0]++; continue;
case 114: b[1]++;continue;
case 98: b[2]++; continue;
case 112: b[3]++; continue;
case 111: b[4]++; continue;
}
}
if(n==-1)
{
for(i=0;i<5;i++)
{
if(b[i]>b[max])
max=i;
}
}
puts(c[max]);
for(i=0;i<5;i++)
b[i]=0;
}
} 展开
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004
#include<stdio.h>
#include<string.h>
int main()
{
int n,max,i;
int b[5]={0,0,0,0,0};
char a[1001];
char c[15][15]={"green","red","blue","pink","orange"};
while(scanf("%d",&n)!=EOF,n!=0)
{ if(!(n>0&&n<=1000))
continue;
max=0;
getchar();
while(n--)
{
gets(a);
switch(a[0])
{
case 103: b[0]++; continue;
case 114: b[1]++;continue;
case 98: b[2]++; continue;
case 112: b[3]++; continue;
case 111: b[4]++; continue;
}
}
if(n==-1)
{
for(i=0;i<5;i++)
{
if(b[i]>b[max])
max=i;
}
}
puts(c[max]);
for(i=0;i<5;i++)
b[i]=0;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询