CSP第一题参考解答2013~2019

CSP第一题参考解答

201312-1C

#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;
}

201403-1C

#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;
}

201409-1C

#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 if(a[i]+1==a[i+1])
c++;
printf("%d",c);
return 0;
}

201412-1C

#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;
}

201503-1C

#include
int main()
{
short m,n,i,j,a[1000][1000];
scanf("%hd%hd",&n,&m);
for(i=0;i for(j=0;j scanf("%hd",&a[i][j]);
for(i=m-1;i>=0;i–)
{
for(j=0;j printf("%hd “,a[j][i]);
printf(”\n");
}
return 0;
}

201509-1C

#include
int main()
{
int n,a[1001],c=0,i,j;
scanf("%d",&n);
for(i=0;i scanf("%d",&a[i]);
i=0;
while(i {
j=i+1;
while(j j++;
i=j;
c++;
}
printf("%d",c);
return 0;
}

201512-1C

#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;
}

201604-1C

#include
#include
int main()
{
int a[1001],b[1001]={0},n,i,s=0;
scanf("%d",&n);
for(i=0;i scanf("%d",&a[i]);
for(i=1;i b[i]=a[i] for(i=1;i if(b[i]*b[i+1]==-1) s++;
printf("%d",s);
return 0;
}

201609-1C

#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;
}

201612-1C

#include
int main()
{
int n,a[1001],i,j,big,small,find=0;
scanf("%d",&n);
for(i=0;i scanf("%d",&a[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;
}

201703-1C

#include
int main()
{
int n,k,i=0,a[1001],s=0,num=0;
scanf("%d %d",&n,&k);
for(i=0;i scanf("%d",&a[i]);
i=0;
while(i {
s=0;
while(s s+=a[i++];
num++;
}
printf("%d",num);
return 0;
}

201709-1C

#include
int main()
{
int N,a,b,c;
scanf("%d",&N);
a=N/50;
b=(N-a50)/30;
c=(N-a
50-b30)/10;
printf("%d",a
7+b*4+c);
return 0;
}

201712-1C

#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 if(a[i+1]-a[i] min=a[i+1]-a[i];
printf("%d",min);
return 0;
}

201803-1C

#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;
}

201809-1C

#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 b[i]=(a[i-1]+a[i]+a[i+1])/3;
for(i=1;i<=n;i++)
printf("%d ",b[i]);
return 0;
}

201812-1C

#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;
}

201903-1C

#include
int main()
{
int n,i,max,min;
int a[100000];
float mid;
scanf("%d",&n);
for(i=0;i scanf("%d",&a[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;
}

你可能感兴趣的:(CSP试题)