2014-02-27 0:05
这个题自己感觉就是结构体排序的问题 ,不过细节问题好像很多 ,,而且还得把题读得十分明白 ,这种超长的题目,果然还要锻炼自己英语功底 ,那几个足球术语都是海词现查的
今天(应该是昨天了) 没写完 明天(也就是今天) 继续把这个弄完 STL用的不好问题很多
2014-02-27 9:45
弄好了 提交了3次才过 ,这里有两个需要注意的地方
Lexicographic Order 指的是忽略大小写的字典序 不是Ascii序
还有 最后结尾不能多输出回车 否则都是WA 我就栽这儿了 = =
还有 用sort时 好像不可以给set排序? 这个需要google下
SET集合没有顺序的概念 所以不能用排序
一下是百度知道网友的回答 引用 链接
你无法用STL里的sort算法对容器set作排序。set本身就是一种有序的容器。 set主要用于不常变动的数据,对其数据的变动,只能是删除旧的,然后再插入新的,这点从它的iterator就能看出来,它的iterator是const的。你可以在初始化set的时候,指定比较排序的方法,或者干脆把set转换为其它容器(比如vector),然后再排序。 但无法再装入原来的set,因为原来的set的排序方法已被固化了
写完后看了看题解 ,自己的排序写的比较丑 应该精简代码。
UVA 真的是需要很注意细节 这次调试代码用了40 min 比较长
Problem A: Football (aka Soccer) |
The Problem
Football the most popular sport in the world (americans insist to call it "Soccer", but we will call it "Football"). As everyone knows, Brasil is the country that have most World Cup titles (four of them: 1958, 1962, 1970 and 1994). As our national tournament have many teams (and even regional tournaments have many teams also) it's a very hard task to keep track of standings with so many teams and games played!
So, your task is quite simple: write a program that receives the tournament name, team names and games played and outputs the tournament standings so far.
A team wins a game if it scores more goals than its oponent. Obviously, a team loses a game if it scores less goals. When both teams score the same number of goals, we call it a tie. A team earns 3 points for each win, 1 point for each tie and 0 point for each loss.
Teams are ranked according to these rules (in this order):
- Most points earned.
- Most wins.
- Most goal difference (i.e. goals scored - goals against)
- Most goals scored.
- Less games played.
- Lexicographic order.
The Input
The first line of input will be an integer N in a line alone (0 < N < 1000). Then, will follow N tournament descriptions. Each one begins with the tournament name, on a single line. Tournament names can have any letter, digits, spaces etc. Tournament names will have length of at most 100. Then, in the next line, there will be a number T (1 < T <= 30), which stands for the number of teams participating on this tournament. Then will follow T lines, each one containing one team name. Team names may have any character that have ASCII code greater than or equal to 32 (space), except for '#' and '@' characters, which will never appear in team names. No team name will have more than 30 characters.
Following to team names, there will be a non-negative integer G on a single line which stands for the number of games already played on this tournament. G will be no greater than 1000. Then, G lines will follow with the results of games played. They will follow this format:
team_name_1#goals1@goals2#team_name_2
For instance, the following line:
Team A#3@1#Team B
Means that in a game between Team A and Team B, Team A scored 3 goals and Team B scored 1. All goals will be non-negative integers less than 20. You may assume that there will not be inexistent team names (i.e. all team names that appear on game results will have apperead on the team names section) and that no team will play against itself.
The Output
For each tournament, you must output the tournament name in a single line. In the next T lines you must output the standings, according to the rules above. Notice that should the tie-breaker be the lexographic order, it must be done case insenstive. The output format for each line is shown bellow:
[a]) Team_name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])
Where:
- [a] = team rank
- [b] = total points earned
- [c] = games played
- [d] = wins
- [e] = ties
- [f] = losses
- [g] = goal difference
- [h] = goals scored
- [i] = goals against
There must be a single blank space between fields and a single blank line between output sets. See the sample output for examples.
Sample Input
2 World Cup 1998 - Group A 4 Brazil Norway Morocco Scotland 6 Brazil#2@1#Scotland Norway#2@2#Morocco Scotland#1@1#Norway Brazil#3@0#Morocco Morocco#3@0#Scotland Brazil#1@2#Norway Some strange tournament 5 Team A Team B Team C Team D Team E 5 Team A#1@1#Team B Team A#2@2#Team C Team A#0@0#Team D Team E#2@1#Team C Team E#1@2#Team D
Sample Output
World Cup 1998 - Group A 1) Brazil 6p, 3g (2-0-1), 3gd (6-3) 2) Norway 5p, 3g (1-2-0), 1gd (5-4) 3) Morocco 4p, 3g (1-1-1), 0gd (5-5) 4) Scotland 1p, 3g (0-1-2), -4gd (2-6) Some strange tournament 1) Team D 4p, 2g (1-1-0), 1gd (2-1) 2) Team E 3p, 2g (1-0-1), 0gd (3-3) 3) Team A 3p, 3g (0-3-0), 0gd (3-3) 4) Team B 1p, 1g (0-1-0), 0gd (1-1) 5) Team C 1p, 2g (0-1-1), -1gd (3-4)
© 2001 Universidade do Brasil (UFRJ). Internal Contest 2001.

1 /**UVAOJ 10194 对多个项目进行排序**/ 2 //#define LOCAL 3 #include<iostream> 4 #include<stdio.h> 5 #include<set> 6 #include<string> 7 #include<algorithm> 8 #include<vector> //SET 不能自定义sort函数么? 用了vector问题就解决了 9 using namespace std; 10 11 typedef struct team 12 { 13 string name; 14 //int rank=0; 15 int points=0; 16 int played=0; 17 int wins=0; 18 int ties = 0; 19 int lose = 0; //输的比赛次数 20 int losses = 0; //输球几个 21 int differ = 0; 22 int goals = 0; 23 }team; 24 25 bool cmp(const team *a, const team*b) //自定义比较函数 26 { 27 if (a->points > b->points) return true; 28 else if (a->points < b->points) return false; 29 else 30 { 31 if (a->wins>b->wins) return true; 32 else if (a->wins < b->wins) return false; 33 else 34 { 35 if (a->differ>b->differ) return true; 36 else if (a->differ < b->differ) return false; 37 else 38 { 39 if (a->goals>b->goals) return true; 40 else if (a->goals < b->goals) return false; 41 else 42 { 43 if (a->played<b->played) return true; 44 else if (a->played > b->played) return false; 45 else 46 { 47 string tmpa, tmpb; 48 tmpa = a->name; 49 tmpb = b->name; 50 for (int oo = 0; oo < tmpa.size(); oo++) tmpa[oo] = tolower(tmpa[oo]); 51 for (int oo = 0; oo < tmpb.size(); oo++) tmpb[oo] = tolower(tmpb[oo]); 52 return tmpa < tmpb; 53 } 54 } 55 } 56 } 57 } 58 } 59 60 int main(void) 61 { 62 #ifdef LOCAL 63 freopen("10194.out","w",stdout); 64 #endif 65 string game; 66 int matches; 67 int num; 68 scanf("%d", &matches); 69 getchar(); //吃回车 70 for (int i = 0; i < matches; i++) 71 { 72 getline(cin, game); 73 scanf("%d", &num); 74 getchar(); //吃回车 75 vector<team*> T; 76 team tmp[32]; 77 for (int oo = 0; oo < num; oo++) 78 { 79 getline(cin, tmp[oo].name); 80 T.push_back(&tmp[oo]); 81 } //存入各个小组信息 82 scanf("%d", &num); //比赛场数 83 getchar(); //再吃回车 84 for (int oo = 0; oo < num; oo++) 85 { 86 string data; //读入信息的区域 87 getline(cin, data); 88 string cur; 89 int cnt = 0; 90 team *curteama,*curteamb; 91 int scorea = 0 , scoreb = 0; 92 while (data[cnt] != '#') cur += data[cnt++]; 93 for (vector<team*>::iterator i = T.begin(); i != T.end(); i++) 94 if ((*i)->name == cur) curteama = *i; //定位到当前队伍a 95 cnt++; 96 while (data[cnt] != '@') //读取比分 先读 a team 97 { 98 scorea = scorea * 10 + data[cnt] - '0'; 99 cnt++; 100 } 101 cnt++; 102 while (data[cnt] != '#') 103 { 104 scoreb = scoreb * 10 + data[cnt] - '0'; //再读b team 105 cnt++; 106 } 107 cur.clear(); //不能忘记清空cur 108 cnt++; 109 while (data[cnt] != '