精 挑 细 选
来源:互联网 发布: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;}
阅读全文
0 0
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- 精 挑 细 选
- nyoj_263精 挑 细 选
- ACM-精 挑 细 选
- 1172 -- 精 挑 细 选
- 精 挑 细 选 263
- 精 挑 细 选 20
- 42.精 挑 细 选
- 南阳理工:精 挑 细 选
- C++设计模式之观察者模式
- 简单使用makefile V1.0
- 数通平台软件中的概念:组件
- 你所不知道的腾讯和马化腾——一封腾讯内部的员工信
- 多线程应用场景
- 精 挑 细 选
- 马化腾:我最大的担忧,就是越来越看不懂年轻人的喜好
- 转载:Linux TCP队列相关参数的总结
- 注销与登录Kindle电子书阅览工具
- 狐狸分奶酪(codeforces 371b)
- H5基础知识第九课时(JS运算符)
- 电脑定时弹出MySql命令框
- H5基础知识第九课时(JS判断语句)
- Amazon Aurora 学习