您的位置:首页 > 其它

POJ 1547 Clay Bully 结构体数组使用题意理解

2010-11-27 20:47 357 查看
这题很简单,可以设置结构体保存三维及姓名,求出体积最大的人和最小的人输出即可。

由于没有注意输出"."而贡献了一次WA,囧

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
struct stu{
stu(){}
string name;
int d;
}s[1000];
int comp(const void * a,const void * b){
return ((stu*)a)->d - ((stu*)b)->d;
}
int main(){
int n,i,a,b,c,dd;
while(1){
cin>>n;
if (n == -1)
break;
for (i = 0 ;i < n;i++)
{
cin>>a>>b>>c;
dd = a*b*c;
s[i].d = dd;
cin>>s[i].name;
}
qsort(s,n,sizeof(s[0]),comp);
cout<<s[--n].name<<" took clay from "<<s[0].name<<"."<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: