精 挑 细 选
Time Limit:1000MS Memory Limit:65536K
Total Submit:38 Accepted:28
Description
小王是公司的仓库管理员,一天,他接到了这样一个任务:从仓库中找出一根钢管。这听起来不算什么,但是这根钢管的要求可真是让他犯难了,要求如下:
1、 这根钢管一定要是仓库中最长的;
2、 这根钢管一定要是最长的钢管中最细的;
3、 这根钢管一定要是符合前两条的钢管中编码最大的(每根钢管都有一个互不相同的编码,越大表示生产日期越近)。
相关的资料到是有,可是,手工从几百份钢管材料中选出符合要求的那根……
要不,还是请你编写个程序来帮他解决这个问题吧。
Input
第一行是一个整数N(N<=10)表示测试数据的组数)
每组测试数据的第一行 有一个整数m(m<=1000),表示仓库中所有钢管的数量,
之后m行,每行三个整数,分别表示一根钢管的长度(以毫米为单位)、直径(以毫米为单位)和编码(一个9位整数)。
Output
对应每组测试数据的输出只有一个9位整数,表示选出的那根钢管的编码,
每个输出占一行
Sample Input
2
2
2000 30 123456789
2000 20 987654321
4
3000 50 872198442
3000 45 752498124
2000 60 765128742
3000 45 652278122
Sample Output
987654321
752498124
Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1172 {
/// <summary>
/// 实际上这题就是简单的结构体排序,但是这样写也可以
/// </summary>
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
while (n-- > 0) {
int m = int.Parse(Console.ReadLine());
int[] a = new int[1001], b = new int[1001], c = new int[1001];
for (int i = 0; i < m; i++) {
string[] sb = Console.ReadLine().Split();
a[i] = int.Parse(sb[0]);
b[i] = int.Parse(sb[1]);
c[i] = int.Parse(sb[2]);
}
int max = 0, min = 1000000, mmax = 0;
for (int i = 0; i < m; i++) if (a[i] > max) max = a[i];//先找到最长的
for (int j = 0; j < m; j++) if (a[j] == max && b[j] < min) min = b[j];//然后找到最长中的最细的
for (int i = 0; i < m; i++) if (a[i] == max && b[i] == min && c[i] > mmax) mmax = c[i];//然后找到最长中的最细的编码最大的
Console.WriteLine(mmax);
}
}
}
}