杭电acm1004为什么老是提示Runtime Error(ACCESS_VIOLATION),请牛人帮我看看哪错了?谢谢啦!!!
#include<stdio.h>#include<string.h>intmax(intcounter[],intn){intmax=0;intc;for(inti=0...
#include<stdio.h>
#include<string.h>
int max(int counter[],int n)
{
int max=0;
int c;
for(int i=0;i<n;i++)
{
if(counter[i]>=max)
{
max=counter[i];
c=i;
}
}
return c;
}
int main()
{
char color[16][1001];
char pr[16];
int counter[1001];
int n,c;
while(scanf("%d",&n))
{
if(n==0) return 0;
else
{
for(int i=0;i<n;i++)
counter[i]=0;
scanf("%s",color[0]);
counter[0]=1;
for(int i=1;i<n;i++)
{
scanf("%s",pr);
strcpy(color[i],pr);
int k=i-1;
if(strcmp(color[k],color[i])==0 && k>=0)
{
counter[k]+=1;
counter[i]=counter[k];
k--;
}
else
counter[i]+=1;
}
c=max(counter,n);
printf("%s\n",color[c]);
}
}
return 0;
} 展开
#include<string.h>
int max(int counter[],int n)
{
int max=0;
int c;
for(int i=0;i<n;i++)
{
if(counter[i]>=max)
{
max=counter[i];
c=i;
}
}
return c;
}
int main()
{
char color[16][1001];
char pr[16];
int counter[1001];
int n,c;
while(scanf("%d",&n))
{
if(n==0) return 0;
else
{
for(int i=0;i<n;i++)
counter[i]=0;
scanf("%s",color[0]);
counter[0]=1;
for(int i=1;i<n;i++)
{
scanf("%s",pr);
strcpy(color[i],pr);
int k=i-1;
if(strcmp(color[k],color[i])==0 && k>=0)
{
counter[k]+=1;
counter[i]=counter[k];
k--;
}
else
counter[i]+=1;
}
c=max(counter,n);
printf("%s\n",color[c]);
}
}
return 0;
} 展开
展开全部
#include<iostream>
using namespace std;
struct Balloon{
int cnt;
char name[20];
}Ball[1010];
int main()
{
int n;
int i,j,t;
int max=0,count=0;
char ch[20];
while(cin>>n&&n)
{
for(i=0;i<n;i++)
{
cin>>ch;
if(i==0)
{
Ball[count].cnt=1;
strcpy(Ball[count++].name,ch);
}
max = 1;
for(j=0;j<count&&max;j++)
if(strcmp(ch,Ball[j].name)==0)
{
Ball[j].cnt++;
max = 0;
}
if(max)
{
Ball[count].cnt=1;
strcpy(Ball[count++].name,ch);
}
}
max = 0;
for(i=0;i<count;i++)
if(max<Ball[i].cnt)
{
max=Ball[i].cnt;
t=i;
}
cout<<Ball[t].name<<endl;
count=0;
max=0;
}
return 0;
}
using namespace std;
struct Balloon{
int cnt;
char name[20];
}Ball[1010];
int main()
{
int n;
int i,j,t;
int max=0,count=0;
char ch[20];
while(cin>>n&&n)
{
for(i=0;i<n;i++)
{
cin>>ch;
if(i==0)
{
Ball[count].cnt=1;
strcpy(Ball[count++].name,ch);
}
max = 1;
for(j=0;j<count&&max;j++)
if(strcmp(ch,Ball[j].name)==0)
{
Ball[j].cnt++;
max = 0;
}
if(max)
{
Ball[count].cnt=1;
strcpy(Ball[count++].name,ch);
}
}
max = 0;
for(i=0;i<count;i++)
if(max<Ball[i].cnt)
{
max=Ball[i].cnt;
t=i;
}
cout<<Ball[t].name<<endl;
count=0;
max=0;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询