北大ACM poj1547 Clay Bully

来源:互联网 发布:mac怎么升级到10.13 编辑:程序博客网 时间:2024/05/30 19:33

Clay Bully

Description

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

310 10 2 Jill5 3 10 Will5 5 10 Bill42 4 10 Cam4 3 7 Sam8 11 1 Graham6 2 7 Pam-1

Sample Output

Bill took clay from Will.Graham took clay from Cam.

 

//1547 //计算每个人拥有泥巴的大小,也就是体积,输入长宽高,体积最小和最大的就是要求的。#include<stdio.h>#include<stdlib.h>typedef struct Ren{int V;char na[9];}Ren;Ren ren[9];int cmp(const void *a,const void *b){return (*(Ren *)a).V - (*(Ren *)b).V; }main(){int n,a,b,c,i; while(scanf("%d",&n),~n)//n为-1结束 {for(i=0;i<n;i++){scanf("%d%d%d%s",&a,&b,&c,ren[i].na);//输入数据 ren[i].V=a*b*c;//计算体积,存入结构体 }qsort(ren,n,sizeof(ren[0]),cmp);//按体积排序 printf("%s took clay from %s.\n",ren[n-1].na,ren[0].na);}} 


 

原创粉丝点击