精 挑 细 选

来源:互联网 发布:java递归树形数据结构 编辑:程序博客网 时间:2024/05/22 12:32

精 挑 细 选

时间限制:3000 ms  |  内存限制:65535 KB
难度:1
描述
小王是公司的仓库管理员,一天,他接到了这样一个任务:从仓库中找出一根钢管。这听起来不算什么,但是这根钢管的要求可真是让他犯难了,要求如下:
1
 这根钢管一定要是仓库中最长的;
2
 这根钢管一定要是最长的钢管中最细的;
3
 这根钢管一定要是符合前两条的钢管中编码最大的(每根钢管都有一个互不相同的编码,越大表示生产日期越近)。
相关的资料到是有,可是,手工从几百份钢管材料中选出符合要求的那根…… 
要不,还是请你编写个程序来帮他解决这个问题吧。
输入
第一行是一个整数N(N<=10)表示测试数据的组数)
每组测试数据的第一行 有一个整数m(m<=1000),表示仓库中所有钢管的数量,
之后m行,每行三个整数,分别表示一根钢管的长度(以毫米为单位)、直径(以毫米为单位)和编码(一个9位整数)。
输出
对应每组测试数据的输出只有一个9位整数,表示选出的那根钢管的编码,
每个输出占一行
样例输入
222000 30 1234567892000 20 98765432143000 50 8721984423000 45 7524981242000 60 7651287423000 45 652278122
样例输出
987654321752498124
来源
2008年小学生程序设计友谊赛试题

上传者


问题:结构体进行比大小的问题。

代码:

#include <iostream>  #include <stdio.h>   #include <string.h>  #include <math.h>  #include <vector>  #include <queue>  #include <stack>  #include <map>  #include <string>  #include <algorithm>  #include <iomanip>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */struct tuple{int length;int diameter;int id;bool operator <(const tuple &t)const{  //将最长 最细 编号最大定义为最小 if(length<t.length){return false;}if(length>t.length){return true;}if(diameter>t.diameter){return false;}if(diameter<t.diameter){return true;}if(id<t.id){return false;}if(id>t.id){return true;}return false;}//tuple& operator =(const tuple &t)const{//length=t.length;//diameter=t.diameter;//id=t.id;//return this;//}void init(tuple t){length=t.length;diameter=t.diameter;id=t.id;}};int main(int argc, char** argv) {/*freopen("file/input.txt","r",stdin);freopen("file/output.txt","w",stdout);*/int n;scanf("%d",&n);while(n--){int m;scanf("%d",&m);tuple min;tuple t;scanf("%d%d%d",&t.length,&t.diameter,&t.id);min=t;while(--m){tuple t;scanf("%d%d%d",&t.length,&t.diameter,&t.id);if(t<min){min=t;}//printf("%d\n",min.id);}printf("%d\n",min.id);}return 0;}