题目内容:
用结构体定义时钟类型,编程从键盘任意输入两个时间(例如4时55分和1时25分),计算并输出这两个时间之间的间隔。要求不输出时间差的负号。结构体类型定义如下:
typedef struct clock
{
int hour;
int minute;
int second;
} CLOCK;
函数原型: CLOCK CalculateTime(CLOCK t1, CLOCK t2);
函数功能:计算并返回两个时间t1和t2之间的差
typedef struct clock
{
int hour;
int minute;
int second;
} CLOCK;
CLOCK CalculateTime(CLOCK t1, CLOCK t2);
int main()
{
CLOCK t1, t2, s;
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);
s = CalculateTime(t1, t2);
printf("%dhour,%dminute\n", s.hour, s.minute);
return 0;
}
CLOCK CalculateTime(CLOCK t1, CLOCK t2)
{
CLOCK t3;
//总分钟数
int s = fabs((t1.hour * 60 + t1.minute) - (t2.hour * 60 + t2.minute));
t3.hour = s / 60;
t3.minute = s % 60;
t3.second = 0;
return t3;
}
题目内容:
某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,每项奖学金获取的条件分别如下:
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元。
现在给出若干学生的相关数据(假设总有同学能满足获得奖学金的条件),请编程计算哪些同学获得的奖金总数最高。
结构体类型定义如下:
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 FindMax(WIN student[], int n);
#define N 30
typedef struct winners
{
char name[20];
int finalScore;
int classScore;
char work;
char west;
int paper;
int scholarship;
} WIN;
int FindMax(WIN student[], int n);
int main()
{
WIN stu[N];
int n, max, scholarship;
printf("Input n:");
scanf("%d", &n);
for (int i = 0; i < n; ++i)
{
scholarship = 0;
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);
if(stu[i].finalScore > 80 && stu[i].paper >= 1)
{
scholarship += 8000;
}
if(stu[i].finalScore > 85 && stu[i].classScore > 80)
{
scholarship += 4000;
}
if(stu[i].finalScore > 90)
{
scholarship += 2000;
}
if(stu[i].finalScore > 85 && stu[i].west == 'Y')
{
scholarship += 1000;
}
if(stu[i].classScore > 80 && stu[i].work == 'Y')
{
scholarship += 850;
}
stu[i].scholarship = scholarship;
printf("name:%s,scholarship:%d\n", stu[i].name, stu[i].scholarship);
}
max = FindMax(stu, n);
printf("%s get the highest scholarship %d\n", stu[max].name, stu[max].scholarship);
return 0;
}
int FindMax(WIN student[], int n)
{
int max = 0;
for (int i = 1; i <= n; ++i)
{
if(student[max].scholarship < student[i].scholarship)
{
max = i;
}
}
return max;
}
题目内容:
现在要评选最牛群主,已知有3名最牛群主的候选人(分别是tom,jack和rose),有不超过1000人参与投票,最后要通过投票评选出一名最牛群主,从键盘输入每位参与投票的人的投票结果,即其投票的候选人的名字,请你编程统计并输出每位候选人的得票数,以及得票数最多的候选人的名字。候选人的名字中间不允许出现空格,并且必须小写。若候选人名字输入错误,则按废票处理。
typedef struct leader
{
char name[10];
int vote;
} LEADER;
int main()
{
LEADER leader[] = {{"tom", 0},
{"jack", 0},
{"rose", 0}};
int n, max = 0;
char name[10];
printf("Input the number of electorates:");
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
{
printf("Input vote %d:", i);
scanf("%s", name);
if (strcmp(name, leader[0].name) == 0)
{
leader[0].vote += 1;
}
else if (strcmp(name, leader[1].name) == 0)
{
leader[1].vote += 1;
}
else if (strcmp(name, leader[2].name) == 0)
{
leader[2].vote += 1;
}
}
printf("Election results:\n");
for (int j = 0; j < 3; ++j)
{
if (leader[max].vote < leader[j + 1].vote)
{
max = j + 1;
}
printf("%s:%d\n", leader[j].name, leader[j].vote);
}
printf("%s wins\n", leader[max].name);
return 0;
}
题目内容:请输入星期几的第一个字母(不区分大小写)来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母(小写),否则输出“data error”。
int main()
{
char *weekDay[7] = {"sunday\n", "monday\n", "tuesday\n", "wednesday\n", "thursday\n", "friday\n", "saturday\n"};
char c1, c2;
int count = 0, pos = 0, flag = 0, index[7];
printf("please input the first letter of someday:\n");
scanf(" %c", &c1);
//如果用户输入的是大写就转换成小写
if(c1 >= 'A' && c1 <= 'Z')
{
c1 += 32;
}
for (int i = 0; i < 7; ++i)
{
//比较首字符是否相同
if(*weekDay[i] == c1)
{
//首字符相同的将索引存入index数组
index[count] = i;
pos = i;
count++;
}
}
if(count == 0)
{
printf("data error\n");
}
else if(count > 1)
{
printf("please input second letter:\n");
scanf(" %c", &c2);
//遍历index数组
for (int i = 0; i < count; ++i)
{
//与第二个字符进行比较
if(c2 == *(*(weekDay + index[i]) + 1))
{
pos = index[i];
flag = 1;
}
}
if(flag)
{
printf("%s", weekDay[pos]);
}
else
{
printf("data error\n");
}
}
else
{
printf("%s", weekDay[pos]);
}
return 0;
}