描述
小王是公司的仓库管理员,一天,他接到了这样一个任务:从仓库中找出一根钢管。这听起来不算什么,但是这根钢管的要求可真是让他犯难了,要求如下:
1、 这根钢管一定要是仓库中最长的;
2、 这根钢管一定要是最长的钢管中最细的;
3、 这根钢管一定要是符合前两条的钢管中编码最大的(每根钢管都有一个互不相同的编码,越大表示生产日期越近)。
相关的资料到是有,可是,手工从几百份钢管材料中选出符合要求的那根……
要不,还是请你编写个程序来帮他解决这个问题吧。
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
样例输出
-
98765432175249812
-
这真是我写过的最长的程序QAQ,我太笨了,想不出来什么好办法,下面附上最优程序import java.util.*; public class Main { static Comparator<Pipe> com_Lon=new Comparator<Pipe>() { @Override public int compare(Pipe o1, Pipe o2) { return o1.lon-o2.lon; } }; static Comparator<Pipe> com_Dia=new Comparator<Pipe>() { @Override public int compare(Pipe o1, Pipe o2) { return o1.dia-o2.dia; } }; static Comparator<Pipe> com_Code=new Comparator<Pipe>() { @Override public int compare(Pipe o1, Pipe o2) { return o1.code-o2.code; } }; public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); while(n-->0){ int m =in.nextInt(); List<Pipe> st=new ArrayList<Pipe>(); List<Pipe> st1=new ArrayList<Pipe>(); List<Pipe> st2=new ArrayList<Pipe>(); for (int i = 1; i <=m; i++){ int lon=in.nextInt(); int dia=in.nextInt(); int code=in.nextInt(); Pipe p=new Pipe(lon, dia, code); st.add(p); } Collections.sort(st, com_Lon); int maxL=st.get(st.size()-1).lon; for (int i = 0; i < st.size(); i++) { if(st.get(i).lon==maxL) st1.add(st.get(i)); }; Collections.sort(st1, com_Dia); int minD=st1.get(0).dia; for (int i = 0; i < st1.size(); i++) { if(st1.get(i).dia==minD) st2.add(st1.get(i)); } Collections.sort(st2, com_Code); System.out.println(st2.get(st2.size()-1).code); } } } class Pipe{ int lon; int dia; int code; Pipe(int l,int d,int c){ this.lon=l; this.dia=d; this.code=c; } }
-
- #include<stdio.h>
- int main()
- {
- int n,m,i,a,b,c,x,y,z;
- scanf("%d",&n);
- while(n--)
- {
- scanf("%d",&m);
- a=0;b=0;c=0;
- for(i=0;i<m;i++)
- {
- scanf("%d%d%d",&x,&y,&z);
- if(x>a||x==a&&y<b||x==a&&y==b&&z>c) { a=x;b=y;c=z; }
- }
- printf("%d\n",c);
- }
- return 0;
- }