JOJ ACM 1061

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 B
C D
A D
C B
D B
C 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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值