1 计算时间差V2.0(4分) 题目内容:用结构体定义时钟类型,编程从键盘任意输入两个时间(例如4时55分和1时25分),计算并输出这两个时间之间的间隔。要求不输出时间差的负号。结构体类型定义如下:typedef struct clock
{ int hour;
int minute;
int second;} CLOCK;
#include<stdio.h>
#include<math.h>
typedef struct clock
{
int hour;
int minute;
int second;
} CLOCK;
int main()
{
CLOCK t1,t2,t3;
int m1=0,m2=0,m3=0;
printf( "Input time one:(hour,minute):");
scanf( "%d,%d",&t1.hour ,&t1.minute );
printf("Input time two: (hour,minute):");
scanf( "%d,%d",&t2.hour ,&t2.minute );
m1=t1.hour *60+t1.minute ;
m2=t2.hour *60+t2.minute ;
m3=m1-m2;
t3.hour =m3/60;
t3.minute =m3%60;
if(t3.hour<0)
t3.hour =t3.hour *(-1);
if(t3.minute <0)
t3.minute =t3.minute *(-1);
printf("%dhour,%dminute\n",t3.hour ,t3.minute );
return 0;
}
2 奖学金发放(4分) 题目内容:某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,每项奖学金获取的条件分别如下:1) 院士奖学金:期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生每人均可获得8000元;2) 五四奖学金:期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生每人均可获得4000元;3) 成绩优秀奖:期末平均成绩高于90分(>90)的学生每人均可获得2000元;4) 西部奖学金:期末平均成绩高于85分(>85)的西部省份学生每人均可获得1000元;5) 班级贡献奖:班级评议成绩高于80分(>80)的学生干部每人均可获得850元;只要符合上述条件就可获得相应的奖项,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。例如姚明的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金和班级贡献奖,奖金总数是4850元。现在给出若干学生的相关数据(假设总有同学能满足获得奖学金的条件),请编程计算哪些同学获得的奖金总数最高。结构体类型定义如下:
#include<stdio.h>
typedef struct winners
{
char name[20];
int finalScore;
int classScore;
char work;
char west;
int paper;
int scholarship;
} WIN;
void Addup(WIN stu[], int n)
{
int i;
for(i=0;i<n;i++)
{
printf("Input name:");
scanf("%s",stu[i].name );
printf("Input final score:");
scanf("%d",&stu[i].finalScore );
printf("Input class score:");
scanf("%d",&stu[i].classScore );
printf("Class cadre or not?(Y/N):");
scanf(" %c" ,&stu[i].work );
printf("Students from the West or not?(Y/N):");
scanf(" %c" ,&stu[i].west );
printf("Input the number of published papers:");
scanf( "%d",&stu[i].paper );
stu[i].scholarship =0;
if(stu[i].finalScore >80&&stu[i].paper >0)
stu[i].scholarship+=8000;
if(stu[i].finalScore >85&&stu[i].classScore >80)
stu[i].scholarship+=4000;
if(stu[i].finalScore>90)
stu[i].scholarship +=2000;
if(stu[i].finalScore>85&&stu[i].west =='Y')
stu[i].scholarship +=1000;
if(stu[i].finalScore>80&&stu[i].work =='Y')
stu[i].scholarship +=850;
printf( "name:%s,scholarship:%d\n",stu[i].name ,stu[i].scholarship );
}
}
int FindMax(WIN student[], int n)
{
int i,k=0;
for(i=0;i<n;i++)
{
if(student[i].scholarship>student[k].scholarship )
k=i;
}
return k;
}
int main()
{
WIN stu[30];
int n,b;
printf("Input n:");
scanf("%d",&n);
Addup(stu,n);
b=FindMax(stu,n);
printf("%s get the highest scholarship %d\n",stu[b].name ,stu[b].scholarship );
return 0;
}
3 评选最牛群主v1.0(4分) 题目内容:现在要评选最牛群主,已知有3名最牛群主的候选人(分别是tom,jack和rose),有不超过1000人参与投票,最后要通过投票评选出一名最牛群主,从键盘输入每位参与投票的人的投票结果,即其投票的候选人的名字,请你编程统计并输出每位候选人的得票数,以及得票数最多的候选人的名字。候选人的名字中间不允许出现空格,并且必须小写。若候选人名字输入错误,则按废票处理。
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,count1=0,count2=0,count3=0;
char name[10];
printf("Input the number of electorates:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Input vote %d:",i);
scanf("%s",name);
if(strcmp("tom",name)==0)
count1++;
if(strcmp("jack",name)==0)
count2++;
if(strcmp("rose",name)==0)
count3++;
}
printf("Election results:\n");
printf("%s:%d\n","tom",count1);
printf("%s:%d\n","jack",count2);
printf("%s:%d\n","rose",count3);
if(count1>count2&&count1>count3)
printf("%s wins\n","tom");
if(count2>count1&&count2>count3)
printf("%s wins\n","jack");
if(count3>count1&&count2<count3)
printf("%s wins\n","rose");
return 0;
}
4 星期判断(4分) 题目内容:请输入星期几的第一个字母(不区分大小写)来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母(小写),否则输出“data error”。程序运行结果示例1:
#include<stdio.h>
int main()
{
char ch,ch1;
printf("please input the first letter of someday:\n");
scanf(" %c" ,&ch);
switch(ch)
{
case 's':case 'S':printf("please input second letter:\n");
scanf(" %c",&ch1);
if(ch1=='a')
{
printf("saturday\n");break;
}
else if(ch1=='u')
{
printf("sunday\n");break;
}
else
{
printf("data error\n");break;
}
case 'f':case 'F':printf("friday\n");break;
case 't':case 'T':printf("please input second letter:\n");
scanf(" %c",&ch1);
if(ch1=='h')
{
printf("thursday\n");break;
}
else if(ch1=='u')
{
printf("tuesday\n");break;
}
else
{
printf("data error\n");break;
}
case 'w':case 'W':printf("wednesday\n");break;
case 'm':case 'M':printf("monday\n");break;
default:printf("data error\n");break;
}
return 0;
}