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;}
原创粉丝点击