这也是一道水题
#include<stdio.h>
#include<string.h>
struct Person
{
char name[20];
int count;
}leader[3]={"yangguang",0,"Bob",0,"zhengyang",0};
void main()
{
int i,j,t,max;
char leader_name[20];
for(i=1;i<=8;i++)
{
scanf("%s",leader_name);
for(j=0;j<3;j++)
if(strcmp(leader_name,leader[j].name)==0)
leader[j].count++;
}
max=leader[0].count;
for(i=0;i<3;i++)
{
if(leader[i].count>max)
{
max=leader[i].count;
}
}
for(i=0;i<3;i++)
{
if(max==leader[i].count)
t=i;
}
printf("%s\n",leader[t].name);
}
输出坐标
#include<stdio.h>
void main()
{
struct xy
{
double x;
double y;
};
struct xy a,b,c;
int i,j;
scanf("%lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y);
c.x=a.x-b.x;
c.y=a.y-b.y;
if(c.x<0&&c.x>-0.05)c.x=0.0;
if(c.y<0&&c.y>-0.05)c.y=0.0;
printf("(%.1lf, %.1lf)\n",c.x,c.y);
}
这是一个水题
#include<stdio.h>
#define N 3
struct Student
{
char name[20];
float score[3];
float aver;
};
void main()
{
void input(struct Student stu[]);
struct Student max(struct Student stu[]);
void print(struct Student stu);
struct Student stu[N],*p=stu;
input(p);
print(max(p));
}
void input(struct Student stu[])
{
int i;
for(i=0;i<N;i++)
{
scanf("%s %f %f %f",&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
}
}
struct Student max(struct Student stu[])
{
int i,m=0;
for(i=0;i<N;i++)
if(stu[i].aver>stu[m].aver)m=i;
return stu[m];
}
void print(struct Student stud)
{
printf("%s %.2f",stud.name,stud.aver);
}
输出学号
#include<stdio.h>
int N;
struct Student
{
int num;
char name[20];
float score;
};
void slove()
{
struct Student stu[10];
int i,max=0;
if(N!=0)
{ for(i=0;i<N;i++)
{
scanf("%d %s %f",&stu[i].num,stu[i].name,&stu[i].score);
}
for(i=1;i<N;i++)
{
if(stu[i].score>stu[max].score)
max=i;
}
printf("%d %s\n",stu[max].num,stu[max].name);
}
}
void main()
{
while(1)
{
scanf("%d",&N);
if(!N)break;
slove();
}
}
输出日期
#include<stdio.h>
void main()
{
int a[10][2],i=0,j=0;
scanf("%d %d",&a[0][0],&a[0][1]);
if(a[0][0]==0&&a[0][1]==0)return 0;
while(1)
{
int max1,max2;
i++,j;
scanf("%d %d",&a[i][0],&a[i][1]);
if(a[i][0]==0&&a[i][1]==0)break;
max1=a[i][0];
max2=a[i][1];
for(j=i;((a[j-1][0]==max1&&a[j-1][1]>max2)||(a[j-1][0]>max1))&&j>0;j--)
{
a[j][0]=a[j-1][0];
a[j][1]=a[j-1][1];
}
a[j][0]=max1;
a[j][1]=max2;
}
for(int x=0;x<i;x++)
{
printf("%d %d\n",a[x][0],a[x][1]);
}
}