题目来源:http://poj.org/problem?id=2654
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAXN = 210; int main() { char m1[10], m2[10]; int iWin[MAXN], iLose[MAXN], p1, p2, i, n, m, k = 0; while(~scanf("%d", &n) && n) { scanf("%d", &m); if(k) printf("\n"); memset(iWin, 0, sizeof(iWin)); memset(iLose, 0, sizeof(iLose)); for(i = 0; i < m*n*(n-1)/2; ++i) { scanf("%d %s %d %s", &p1, m1, &p2, m2); if((!strcmp(m1, "rock") && !strcmp(m2, "scissors")) || (!strcmp(m1, "scissors") && !strcmp(m2, "paper")) || (!strcmp(m1, "paper") && !strcmp(m2, "rock"))) iWin[p1]++, iLose[p2]++; if((!strcmp(m1, "rock") && !strcmp(m2, "paper")) || (!strcmp(m1, "paper") && !strcmp(m2, "scissors")) || (!strcmp(m1, "scissors") && !strcmp(m2, "rock"))) iWin[p2]++, iLose[p1]++; } for(i = 1; i <= n; ++i) if(iWin[i] + iLose[i]) printf("%.3lf\n", (double)iWin[i]/(iWin[i] + iLose[i])); else printf("-\n"); ++k; } return 0; }