ACM比賽排名

ACM比賽排名

    Time Limit: 1000 ms 

    Memory Limit: 65535 kB 

    Description

         我們知道,每一年的ACM/ICPC亞洲地區現場賽賽都會有很多很多個代表隊  參賽,於是,怎麼把這些隊伍排序成了組織者最頭疼的問題。後來,他們終於  想出瞭解決方案,那就是——按照網絡賽的做題數排序,如果做題數一樣再按                                      罰時排序,如果罰時又是一樣的,那就只能按照學校名字的字典序排序了
     他們規定:
      1、做題數多的排在前面;
      2、罰時少的排在前面
      3、名字按字母ASCII碼值升序排列,如果第一個字母一樣就比較第二個字    母,以此類推

    Input

Line 1:一個數N(1<= N <= 500),代表進入現場賽的學校數
Line 2 - N + 1:隊伍的名字(不含空格,由大小寫字母組成,長度不超過50)、做題數(正整數)、罰時(正整數)
輸入數據保證不出現三者完全一樣的數據

Output

按輸入的格式把隊伍排序後輸出,case之間輸出空行

Sample Input

2
TeamA 3 200
TeamB 4 500

Sample Output

TeamB 4 500
      TeamA 3 200

這題考的是結構體排序,可以寫一個低效的冒泡排序什麼的,這裏用的是algorithm頭文件中的sort算法。

下面是一篇寫qsort和sort使用的文章,http://wenku.baidu.com/view/667c03c10c22590102029d7a.html

#include <cstdio>
 #include <algorithm>
 #include <cstring>
 using namespace std;
 
 typedef struct TeamInformation
 {
 	char name[55];
 	int rightNums;
 	int totalTime;
 }TeamInformation;
 
 bool cmp( TeamInformation  teamA,  TeamInformation teamB)
 {
 	if ( teamA.rightNums > teamB.rightNums )
 	{
 		return true;
 	}
 	if ( teamA.rightNums < teamB.rightNums )
 	{
 		return false;
 	}
 	if ( teamA.totalTime < teamB.totalTime )
 	{
 		return true;
 	}
 	if ( teamA.totalTime > teamB.totalTime )
 	{
 		return false;
 	}
 	if ( strcmp(teamA.name, teamB.name) < 0 )
 	{
 		return true;
 	}
 	return false;
 }
 
 int main()
 {
 	int N;
 	FILE * fin, * fout;
 	fin = fopen("1.std.in", "r");
 	fout = fopen("1.std.out", "w");
 	TeamInformation teams[510];
 	fscanf(fin, "%d", &N);
 	for ( int i = 0; i < N; i++ )
 	{
 		fscanf(fin, "%s %d %d", teams[i].name, &teams[i].rightNums, &teams[i].totalTime);
 	}
 	sort(teams, teams + N, cmp);
 	for ( int i = 0; i < N; i++ )
 	{
 		fprintf(fout, "%s %d %d\n", teams[i].name, teams[i].rightNums, teams[i].totalTime);
 	}
 
 	return 0;
 }
 




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章