Ms. Terry is a pre-school art teacher who likes to have her students work with clay. One of her assignments is to form a lump of clay into a block and then measure the dimensions of the block. However, in every class, there is always one child who insists on taking some clay from some other child. Since Ms. Terry always gives every child in a class the same amount of clay to begin with, you can write a program that helps Ms. Terry find the bully and victim after she measures each child's finished block.
Input
There are one or more classes of students, followed by a final line containing only the value -1. Each class starts with a line containing an integer, n, which is the number of students in the class, followed by n lines of student information. Each line of student information consists of three positive integers, representing the dimensions of the clay block, followed by the student's first name. There can never be more than 9 students nor less than 2 students in any class. Each student's name is at most 8 characters. Ms. Terry always gives each student at most 250 cubic units of clay. There is exactly one bully and one victim in each class.
Output
For each class print a single line exactly as shown in the sample output.
Sample Input
3
10 10 2 Jill
5 3 10 Will
5 5 10 Bill
4
2 4 10 Cam
4 3 7 Sam
8 11 1 Graham
6 2 7 Pam
-1
Sample Output
Bill took clay from Will.
Graham took clay from Cam.
#include<stdio.h>
#include<string.h>
typedef struct student{
char name[9];
int total;
};
int main(){
int n, i;
int x,y,z;
student stu[10],max,min;
while(scanf("%d",&n),n!=(-1)){
for(i=1;i<=n;i++){
scanf("%d%d%d%s",&x,&y,&z,&stu[i].name);
stu[i].total = x*y*z;
}
(stu[1].total>stu[2].total)
?(max.total=stu[1].total , strcpy(max.name ,stu[1].name),
min.total=stu[2].total , strcpy(min.name,stu[2].name))
:(max.total=stu[2].total,strcpy(max.name,stu[2].name),
min.total=stu[1].total,strcpy(min.name,stu[1].name));
for(i=3;i<=n;i++){
if(stu[i].total>max.total){
max.total=stu[i].total;
strcpy(max.name,stu[i].name);
}
else if(stu[i].total<min.total){
min.total=stu[i].total;
strcpy(min.name,stu[i].name);
}
}
printf("%s took clay from %s.",max.name,min.name);
}
}
这是一个编程问题,要求通过比较学生制作的粘土块体积来找出班上谁拿了谁的粘土。输入包括多个班级的学生粘土块尺寸及名字,输出则是指出每个班级中谁从谁那里拿走了粘土。
236

被折叠的 条评论
为什么被折叠?



