CSP第一题参考解答
#include
#include
int main()
{
int c[10001]={0},i,x,n;
int k=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&x);
c[x]++;
}
for(i=1;i<10001;i++)
if(c[i]>c[k]) k=i;
printf("%d",k);
return 0;
}
#include
#include
int main()
{
int N,a[1001]={0},i,x,c=0;
scanf("%d",&N);
for(i=1;i<=N;i++)
{
scanf("%d",&x);
a[abs(x)]++;
}
for(i=1;i<=N;i++)
if(a[i]==2) c++;
printf("%d",c);
return 0;
}
#include
int main()
{
int n,a[1001]={0},i,k,x,c=0;
scanf("%d",&n);
scanf("%d",&a[1]);
for(i=2;i<=n;i++)
{
scanf("%d",&x);
a[0]=x;
k=i-1;
while(x {
a[k+1]=a[k];
k–;
}
a[k+1]=x;
}
for(i=1;i
c++;
printf("%d",c);
return 0;
}
#include
int main()
{
int n,i,x,a[1001]={0};
scanf("%d",&n);
for(i=0;i
scanf("%d",&x);
a[x]++;
printf("%d ",a[x]);
}
return 0;
}
#include
int main()
{
short m,n,i,j,a[1000][1000];
scanf("%hd%hd",&n,&m);
for(i=0;i
for(i=m-1;i>=0;i–)
{
for(j=0;j
printf(”\n");
}
return 0;
}
#include
int main()
{
int n,a[1001],c=0,i,j;
scanf("%d",&n);
for(i=0;i
i=0;
while(i
j=i+1;
while(j
i=j;
c++;
}
printf("%d",c);
return 0;
}
#include
#include
int main()
{
long int n;
int s=0;
scanf("%ld",&n);
while(n)
{
s+=n%10;
n/=10;
}
printf("%d",s);
return 0;
}
#include
#include
int main()
{
int a[1001],b[1001]={0},n,i,s=0;
scanf("%d",&n);
for(i=0;i
for(i=1;i
printf("%d",s);
return 0;
}
#include
#include
int main()
{
int n,a[1001],i,max=0,t;
scanf("%d",&n);
scanf("%d",&a[0]);
for(i=1;i
scanf("%d",&a[i]);
t=abs(a[i]-a[i-1]);
if(t>max)
max=t;
}
printf("%d",max);
return 0;
}
#include
int main()
{
int n,a[1001],i,j,big,small,find=0;
scanf("%d",&n);
for(i=0;i
for(i=0;i
big=0;small=0;
for(j=0;j
if(a[j]>a[i]) big++;
if(a[j] }
if(big==small)
{
printf("%d",a[i]);
find=1;
break;
}
}
if(!find) printf("-1");
return 0;
}
#include
int main()
{
int n,k,i=0,a[1001],s=0,num=0;
scanf("%d %d",&n,&k);
for(i=0;i
i=0;
while(i
s=0;
while(s
num++;
}
printf("%d",num);
return 0;
}
#include
int main()
{
int N,a,b,c;
scanf("%d",&N);
a=N/50;
b=(N-a50)/30;
c=(N-a50-b30)/10;
printf("%d",a7+b*4+c);
return 0;
}
#include
int main()
{
int n,i,k,a[1001],x,min;
scanf("%d",&n);
scanf("%d",&a[1]);
for(i=2;i<=n;i++)
{
scanf("%d",&x);
a[0]=x;
k=i-1;
while(x a[k+1]=a[k–];
a[k+1]=x;
}
min=10001;
for(i=1;i
printf("%d",min);
return 0;
}
#include
int main()
{
int a,pre=0,s=0,sum=0;
scanf("%d",&a);
while(a!=0)
{
if(a== 1) s=1;
else if(pre== 0 || pre==1) s=2;
else s=s+2;
sum+=s;
pre=a;
scanf("%d",&a);
}
printf("%d",sum);
return 0;
}
#include
int main()
{
int n,a[1001],b[1001],i;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
b[1]=(a[1]+a[2])/2;
b[n]=(a[n-1]+a[n])/2;
for(i=2;i
for(i=1;i<=n;i++)
printf("%d ",b[i]);
return 0;
}
#include
int main()
{
int r,y,g,n,k,t,i,time=0;
scanf("%d%d%d",&r,&y,&g);
scanf("%d",&n);
for(i=0;i
scanf("%d%d",&k,&t);
if(k = = 0||k = = 1 ) time+=t;
else if(k == 2) time+=t+r;
}
printf("%d ",time);
return 0;
}
#include
int main()
{
int n,i,max,min;
int a[100000];
float mid;
scanf("%d",&n);
for(i=0;i
max=a[0]>a[n-1]?a[0]:a[n-1];
min=a[0] if(n%2)
mid=a[n/2];
else mid=(a[n/2-1]+a[n/2])/2.0;
if(mid-(int)(mid)==0)
printf("%d %d %d",max,(int)mid,min);
else printf("%d %.1lf %d",max,mid,min);
return 0;
}