Time Limit: 1 secs, Memory Limit: 256 MB
Description
小明是奶牛场的员工,已知奶牛按品种分为3类,分别编号为1,2,3,小明的任务是找出每一类奶牛的最大产奶量。
给定一个整数N(1<=N<=10,000)代表奶牛的总数,并且给出每头奶牛的编号(1,..,3)以及产奶量(1,…,1,000,000),找出每类奶牛中最大的产奶量。
Input
第一行为T(1<=T<=20 ),代表用例个数。
接下来每个用例中,第一行为一个整数N,代表奶牛总数。
第2…N+1行:每行两个整数m,n,分别代表相对应的奶牛的类别和产奶量。
Output
按照类别号从小到大输出,每行包含类别号,以及该类别下的最大奶牛产奶量。 注意,可能有的类别下一头奶牛也没有,这种情况下不需要输出任何信息(参见Sample Input的第一个用例)。
Sample Input
2
2
1 2
2 5
10
1 5
3 7
3 3
2 4
3 5
2 3
1 7
2 6
3 4
1 2
Sample Output
1 2
2 5
1 7
2 6
3 7
Problem Source
test
^_^ Just do it
#include <iostream>
#include <map>
using namespace std;
int main()
{
int T, N, num1, num2;
map<int, int> Temp;
cin >> T;
while (T--)
{
Temp.clear();
cin >> N;
while (N--)
{
cin >> num1 >> num2;
if (num2 > Temp[num1]) {
Temp[num1] = num2;
}
}
map<int, int> :: iterator i = Temp.begin();
while (i != Temp.end()) {
cout << (*i).first << " " << (*i).second << endl;
++i;
}
}
return 0;
}