南邮 OJ 1387 Pythons

来源:互联网 发布:简述网络贷款的危害 编辑:程序博客网 时间:2024/06/03 14:31

Pythons

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 100            测试通过 : 34 

比赛描述

The fish and game commission in South Florida has been catching and measuring

Burmese Pythons in the Everglades. Needless to say, this is a little scary, since these

critters have been rumored to swallow alligators and young computer programmers. The

game officers have been collecting information about their catches, listing the weight in

pounds, along with the date when the snake was caught. Your job is to produce a list of

snakes in ascending order by weight. For any snakes that have the same weight, they

must be listed in ascending order by date.




输入

The first line contains N, indicating the number of data sets that will follow. For each

dataset, the next line contains S, which indicates the number of snake samples in the

current data set. Then, for each value of S, each of the following lines contain two values:

each Python's weight, followed by the date when the python was caught (in mm/dd/yyyy

order), separated by one space. The dates within each data set are guaranteed to be in

ascending order. Here is a sample dataset:


输出

For each dataset, display the snake's weight, followed by a single space, followed by the

date when the snake was caught. Display the values in order by weight from lowest to

highest. This is called the primary sort. But for any duplicate weight values, the dates

should be in increasing order. For example, in the following sample output, notice the

specific ordering of the dates for the three snakes weighing 120 pounds. Follow ever data

set with a blank line. Here is a sample that matches the sample input data:


样例输入

2
3
85 10/22/2008
66 3/1/2009
76 5/12/2009
6
120 4/10/2009
120 6/5/2009
30 8/21/2009
85 9/2/2009
62 10/22/2009
120 1/12/2010

样例输出

66 3/1/2009
76 5/12/2009
85 10/22/2008
By Kip Irvine
30 8/21/2009
62 10/22/2009
85 9/2/2009
120 4/10/2009
120 6/5/2009
120 1/12/2010

提示

undefined

题目来源

Internet



#include<iostream>#include<algorithm>struct python{int weight,day,month,year;};bool operator<(const python &p1, const python &p2){if(p1.weight !=p2.weight){return p1.weight < p2.weight;}if(p1.year != p2.year){return p1.year < p2.year;}if(p1.month != p2.month){return p1.month < p2.month;}return p1.day < p2.day;}int main(){int cas,n,i;python *p;scanf("%d",&cas);while(cas--){scanf("%d",&n);p = new python[n];for(i=0;i<n;i++){scanf("%d %d/%d/%d",&p[i].weight,&p[i].month,&p[i].day,&p[i].year);}std::sort(p,p+n);for(i=0;i<n;i++){printf("%d %d/%d/%d\n",p[i].weight,p[i].month,p[i].day,p[i].year);}printf("\n");delete[] p;}}






0 0