码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1547 Clay Bully

时间:2015-06-03 08:28:03      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8344   Accepted: 4706

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

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.

CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)
#define MAX_N 10 + 5

using namespace std;

int n;
int a, b, c, mx = 0, mn = 99999999, lx, ln;
char s[10], ans_mx[10], ans_mn[10];

int main(){
    while(scanf("%d", &n) != EOF){
        if(n == -1) break;
        mx = 0, mn = 99999999;
        REP(i, 1, n){
            scanf("%d%d%d", &a, &b, &c);
            scanf("%s", s + 1);
            if(a * b * c > mx){
                mx = a * b * c;//, ans_mx = s;
                REP(i, 1, strlen(s + 1))
                    ans_mx[i] = s[i];
                lx = strlen(s + 1);
            }
            if(a * b * c < mn){
                mn = a * b * c;//, ans_mx = s;
                REP(i, 1, strlen(s + 1))
                    ans_mn[i] = s[i];
                ln = strlen(s + 1);        
            }
        }
        REP(i, 1, lx) cout << ans_mx[i]; 
        cout << " took clay from ";
        REP(i, 1, ln) cout << ans_mn[i];
        cout << . << endl;
    }
    return 0;
}
        

 

 

POJ 1547 Clay Bully

标签:

原文地址:http://www.cnblogs.com/ALXPCUN/p/4548214.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!