POJ 2654 Rock-Paper-Scissors Tournament(水~)

Description
有n个人玩儿k局剪刀石头布,给出每局两个人出的是什么,问每个人的胜率
Input
多组用例,每组用例第一行为两个整数n和k分别表示游戏人数和游戏局数,之后k行每行输入对局两人的动作(paper布,rock石头,scissors剪刀),以0结束输入
Output
对于每组用例,输出n个人的胜率,如果胜率不确定则输出’-‘,相邻两组用例用一空行隔开
Sample Input
2 4
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
2 1
1 rock 2 paper
0
Sample Output
0.333
0.667

0.000
1.000
Solution
简单题,统计每个人输赢次数lost[i]和win[i],如果lost[i]+win[i]=0说明此人未参加比赛,胜率不确定,否则win[i]/(win[i]+lost[i])为该人胜率
Code

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 111
int n,k,win[maxn],lose[maxn];
int main()
{
    int res=0;
    while(~scanf("%d",&n),n)
    {
        if(res++)printf("\n");
        memset(win,0,sizeof(win));
        memset(lose,0,sizeof(lose));
        scanf("%d",&k);
        for(int i=0;i<k*n*(n-1)/2;i++)
        {
            int a,b;char s1[11],s2[11];
            scanf("%d%s%d%s",&a,s1,&b,s2);
            if(s1[0]=='p'&&s2[0]=='r'||s1[0]=='r'&&s2[0]=='s'||s1[0]=='s'&&s2[0]=='p')
                win[a]++,lose[b]++;
            else if(s2[0]=='p'&&s1[0]=='r'||s2[0]=='r'&&s1[0]=='s'||s2[0]=='s'&&s1[0]=='p')
                win[b]++,lose[a]++;
        }
        for(int i=1;i<=n;i++)
            if(win[i]+lose[i])printf("%.3lf\n",1.0*win[i]/(win[i]+lose[i]));
            else printf("-\n");
    }
} 

你可能感兴趣的:(POJ 2654 Rock-Paper-Scissors Tournament(水~))