目录
2014-03-01
#include <stdio.h>
#include <stdlib.h>
#define N 500
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,a[N],i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int t=0;
for(i = 0;i<n-1;i++)
{
for(j=i;j<n;j++)
{
if(a[i]+a[j]==0)
t++;
}
}
printf("%d",t);
return 0;
}
201503-1
#include <stdio.h>
#include <stdlib.h>
#define N 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,m,i,j;
scanf("%d %d",&m,&n);
int a[m][n];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(j=n-1;j>=0;j--)
{
for(i=0;i<m;i++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}
2015-09-1
#include <stdio.h>
#include <stdlib.h>
#define N 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,m,i,j,sum = 0;
int a[N];
scanf("%d",&n);
for(i =0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i = 0;i<n;i++)
{
if(a[i]!=a[i+1])
sum++;
}
printf("%d",sum);
return 0;
}
201512-1
#include <stdio.h>
#include <stdlib.h>
#define N 10000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,m,i,j,sum = 0;
int a[N];
char s[N];
scanf("%s",&s);
/*for(i =0;i<n;i++)
{
scanf("%d",&a[i]);
}*/
for(i = 0;s[i]!='\0';i++)
{
sum+=s[i]-'0';
}
printf("%d",sum);
return 0;
}
201604-1
#include <stdio.h>
#include <stdlib.h>
#define N 10000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,m,i,j,sum = 0;
int a[N];
scanf("%d",&n);
for(i =0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i = 1;i<n-1;i++)
{
if((a[i]<a[i-1]&&a[i]<a[i+1])||(a[i]>a[i-1]&&a[i]>a[i+1]))
sum++;
}
printf("%d",sum);
return 0;
}
201609-1
#include <stdio.h>
#include <stdlib.h>
#define N 10000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,m,i,j,sum = 0,max,time;
int a[N];
scanf("%d",&n);
for(i =0;i<n;i++)
{
scanf("%d",&a[i]);
}
max = 0;
for(i = 1;i<n;i++)
{
if(a[i]-a[i-1]>max||a[i-1]-a[i]>max)
{
if(a[i]-a[i-1]>0)
max = a[i]-a[i-1];
else
max = a[i-1]-a[i];
}
}
printf("%d",max);
return 0;
}
201612-1
#include <stdio.h>
#include <stdlib.h>
#define N 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,i,j,temp,a[N],t,mi=0,ma=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
if(n%2==0)
t = n/2-1;
else
t = n/2;
for(i =0;i<n;i++)
{
if(n%2==0&&a[t]!=a[t+1])
{
printf("-1");
return 0;
}
if(a[i]<a[t])
mi++;
else if(a[i]>a[t])
ma++;
else
continue;
}
if(mi==ma)
printf("%d",a[t]);
else
printf("-1");
return 0;
}
201703-1
#include <stdio.h>
#include <stdlib.h>
#define N 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i,j,a[N],n,k,sum=0,num=0;
scanf("%d %d",&n,&k);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
sum+=a[i];
if(sum>=k)
{
num++;
sum = 0;
}
}
if(sum==0)
printf("%d",num);
else
printf("%d",num+1);
return 0;
}
201709-1
#include <stdio.h>
#include <stdlib.h>
#define N 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,a,b,c,num;
scanf("%d",&n);
a = n/50;
b = (n-a*50)/30;
c = (n-a*50-b*30)/10;
num = a*7+b*4+c;
printf("%d",num);
return 0;
}
201712-1
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define N 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i,j,a[N],n,min=10000;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(abs(a[i]-a[j])<min)
min = abs(a[i]-a[j]);
}
}
printf("%d",min);
return 0;
}
201803-1
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define N 30
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i,j,a[N],n,sum=0,de=0;
//scanf("%d",&n);
i=-1;
do
{
i++;
scanf("%d",&a[i]);
}while(a[i]!=0);
i = 1;
sum = a[0];
de = a[0];
while(a[i]!=0)
{
if(a[i]==1)
{
de = 1;
}
else if(a[i-1]==1&&a[i]==2)
{
de = 2;
}
else if(a[i-1]==2&&a[i]==2)
{
de+=2;
}
sum+=de;
i++;
}
printf("%d",sum);
return 0;
}
201809-1
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define N 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i,j,n,a[N],b[N];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(i==0)
b[i] = (a[i]+a[i+1])/2;
else if(i==n-1)
b[i] = (a[i]+a[i-1])/2;
else
b[i] = (a[i]+a[i-1]+a[i+1])/3;
}
for(i=0;i<n;i++)
{
printf("%d ",b[i]);
}
return 0;
}
201812-1
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define N 1000
typedef struct {
int num;
int s;
}Bn;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int r,y,g;
int n,i,sum=0;
scanf("%d%d%d",&r,&y,&g);
scanf("%d",&n);
Bn a[n];
for(i = 0;i<n;i++)
{
scanf("%d",&a[i].num);
scanf("%d",&a[i].s);
}
for(i=0;i<n;i++)
{
if(a[i].num==0)
sum+=a[i].s;
else if(a[i].num==1)
sum+=a[i].s;
else if(a[i].num==2)
sum+=a[i].s+r;
}
printf("%d",sum);
return 0;
}
201903-1
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define N 1000
#define M 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,i,flag=0;
scanf("%d",&n);
int a[n];
float t;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
if(n%2==0)
t = (a[n/2-1]+a[n/2])*1.0/2;
else
t = a[n/2];
if(t-(int)t!=0)
flag = 1;
if(a[0]<a[n-1])
{
printf("%d ",a[n-1]);
if(flag==0)
printf("%d ",(int)t);
else
printf("%.1f ",t);
printf("%d",a[0]);
}
else
{
printf("%d ",a[0]);
if(flag==0)
printf("%d ",(int)t);
else
printf("%.1f ",t);
printf("%d",a[n-1]);
}
return 0;
}
201909-1
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define N 100
#define M 100
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,m,i,j;
int T=0,K,P[N]={0},max=0;
scanf("%d%d",&n,&m);
int a[N][M+1]={0};
for(i=0;i<n;i++)
{
for(j=0;j<m+1;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<m+1;j++)
{
T += a[i][j];
if(j!=0)
P[i] += a[i][j];
}
if(max<abs(P[i]))
{
max = abs(P[i]);
K = i+1;
}
}
printf("%d %d %d",T,K,max);
return 0;
}
201912-1
#include <stdio.h>
#include <stdlib.h>
#define N 1000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int have7(int n);
int main(int argc, char *argv[]) {
int n;
scanf("%d",&n);
int a=0,b=0,c=0,d=0;
int i=0,j=1;
while(j<=n)
{
i++;
if(i%7==0||have7(i))
{
if(i%4==1)
a++;
else if(i%4==2)
b++;
else if(i%4==3)
c++;
else
d++;
continue;
}
j++;
}
printf("%d\n%d\n%d\n%d\n",a,b,c,d);
return 0;
}
int have7(int n)
{
while(n)
if(n%10==7)return 1;
else n/=10;
return 0;
}
2021-9-1
#include <stdio.h>
#define N 500
#define M 500
#define L 256
int main()
{
int A1[N],A2[N]={0};
int B[N];
int n,i,j,flag,sum1=0,sum2 = 0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&B[i]);
}
A1[0] = B[0];
A2[0] = B[0];
for(i=1;i<n;i++)
{
A1[i] = B[i];
if(B[i]!=B[i-1])
A2[i] = B[i];
}
for(i=0;i<n;i++)
{
sum1+=A1[i];
}
for(i=0;i<n;i++)
{
sum2+=A2[i];
}
printf("%d\n%d",sum1,sum2);
return 0;
}
202009-1
#include <stdio.h>
#include <math.h>
#define N 10000
#define M 500
#define L 256
typedef struct{
int sum;
int a;
}Stu;
int main()
{
int n,a[N][2],i,j,x,y;
Stu sum1[N],temp;
scanf("%d%d%d",&n,&x,&y);
for(i=0;i<n;i++)
{
scanf("%d%d",&a[i][0],&a[i][1]);
}
for(i=0;i<n;i++)
{
sum1[i].sum = pow(a[i][0]-x,2)+pow(a[i][1]-y,2);
sum1[i].a = i+1;
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(sum1[i].sum>sum1[j].sum)
{
temp = sum1[i];
sum1[i] = sum1[j];
sum1[j] = temp;
}
}
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(sum1[i].sum==sum1[j].sum&&sum1[i].a>sum1[j].a)
{
temp = sum1[i];
sum1[i] = sum1[j];
sum1[j] = temp;
}
}
}
printf("%d\n%d\n%d\n",sum1[0].a,sum1[1].a,sum1[2].a);
return 0;
- }