主题:一道简单题,但不知为什么老是提交不通过.
各位高手,我在北大在线做题中做了<<Clay Bully>>(第1547道题),题目虽简单,但老是提交时是"Wrong Answer",但我自己在机上又通过了,不知道哪里错了,找了很久,都找不到.诚恳希望各位能帮手,谢谢!下面是我的程序:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string bully,victim,str;
int min,max,flag;
int n,x,y,h;
cin>>n;
while(n!=-1)
{
min=10000;
max=0;
for(int i=1;i<=n;i++)
{
cin>>x>>y>>h>>str;
flag=x*y*h;
if(flag<min)
{
min=flag;
victim=str;
}
else if(flag>max)
{
max=flag;
bully=str;
}
else;
}
cout<<bully<<" took clay from "<<victim<<'.'<<endl;
cin>>n;
}
return 1;
}
下面是原题:
Clay Bully
Time Limit:1000MS Memory Limit:10000K
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 clays 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(2<=n<=9). 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 <iostream>
#include <string>
using namespace std;
int main()
{
string bully,victim,str;
int min,max,flag;
int n,x,y,h;
cin>>n;
while(n!=-1)
{
min=10000;
max=0;
for(int i=1;i<=n;i++)
{
cin>>x>>y>>h>>str;
flag=x*y*h;
if(flag<min)
{
min=flag;
victim=str;
}
else if(flag>max)
{
max=flag;
bully=str;
}
else;
}
cout<<bully<<" took clay from "<<victim<<'.'<<endl;
cin>>n;
}
return 1;
}
下面是原题:
Clay Bully
Time Limit:1000MS Memory Limit:10000K
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 clays 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(2<=n<=9). 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.