JOJ ACM 1061
来源:互联网 发布:进销存软件源码 编辑:程序博客网 时间:2024/05/17 08:34
1st JOJ Cup Online VContest Warmup Problem
Once two teams have played a game, the winner of that game is ranked better than the loser of the game. Your mission is to rank the teams, i.e. to produce a linearly ordered list starting with the best team, and progressing down to the worst one.
Input Specification
You are given a number of teams and the results of games played by pairs of these teams. Each team will be identified by an upper case letter. The maximum number of teams is 26. Each line contains two upper case letters, separated by one blank space in the input. The two letters on a line indicate the winner and loser of a game played by the two teams.
Output Specification
The output will list all teams on one line. Each team will appear in the list only once. If "X Y" occurs in the input then X will occur somewhere before Y in the output. There may, however, be additional teams between X and Y in the output. You may assume that, for any given input, there will be one unique linear ordering (with no ties) of the teams. In the example, every team played with every other team. There may not, however, be the case for all input.
Sample Input
A BC DA DC BD BC A
Sample Output
C A D B
code:
#include<iostream>using namespace std;struct Team{ char name; int score;}a[26];void init(){ for(int i=0;i<26;i++) { a[i].name = (char)('A'+i); a[i].score = 0; }}void sort(struct Team b[]){ bool flag = false; struct Team temp; for(int i=0;i<25;i++) { flag = false; for(int j=0;j<25;j++) { if(b[j].score < b[j+1].score) { temp = b[j];b[j] = b[j+1];b[j+1] = temp; flag = true; } } if(flag == false) break; }}int main(){char ch;int i=0,flag = 0;init(); while(ch=cin.get(),ch!=EOF){a[ch-65].score++;ch=cin.get();//delete空格ch=cin.get();a[ch-65].score--;ch=cin.get();//delete 回车 }sort(a);for(;i<26;i++){if(a[i].score != 0){ if(flag)cout<<" "; else flag = true; cout<<a[i].name;}}cout<<endl;return 0;}
- JOJ ACM 1061
- JOJ ACM 1237
- JOJ ACM 2155
- JOJ ACM 1148
- JOJ ACM 1146
- JOJ ACM 1107
- JOJ ACM 1149
- JOJ ACM 1184
- ACM JOJ 1062
- ACM JOJ 1007
- ACM JOJ 1023
- JOJ 1061: Rank The Teams 解题报告
- JOJ 2257
- joj 2319
- joj 2653
- JOJ 2687
- joj 2693
- joj 2443
- JOJ ACM 1107
- 买了台MP3
- JOJ ACM 1149
- JOJ ACM 1184
- 一生中最经典的话
- JOJ ACM 1061
- 爆炸也流行!!!
- 第一次在天涯上发贴,就遭到别人的唾骂
- 魔羯和水瓶--此情可待成追忆
- [转]Visual C++中DDB与DIB位图编程全攻略
- 程序员生涯第43天
- [转贴]带USB接口的短信收发最小系统设计
- 关于理想
- 对CSDN社区一点感想.