基础题。
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;
const int MAXN = 105;
int success[MAXN]; //每名选手胜利的次数
int failure[MAXN]; //每名选手失败的次数
int main()
{
int n, k;
int p1, p2; //选手
string s1, s2;
int Case = 0; //测试用例组数(用于规范输出)
while (cin >> n)
{
if (n == 0)
break;
cin >> k;
memset(success, 0, sizeof(success));
memset(failure, 0, sizeof(failure));
for (int i = 0; i < k; i++)
{
cin >> p1 >> s1 >> p2 >> s2;
if (s1 == "rock") {
if (s2 == "paper") {
++failure[p1];
++success[p2];
}
else if (s2 == "scissors") {
++success[p1];
++failure[p2];
}
}
else if (s1 == "paper") {
if (s2 == "rock") {
++success[p1];
++failure[p2];
}
else if (s2 == "scissors") {
++failure[p1];
++success[p2];
}
}
else {
if (s2 == "rock") {
++failure[p1];
++success[p2];
}
else if (s2 == "paper") {
++success[p1];
++failure[p2];
}
}
}
if (++Case > 1)
cout << endl;
for (int i = 1; i <= n; i++)
{
if (success[i] + failure[i] == 0)
cout << "-" << endl;
else
cout << fixed << setprecision(3) << 1.0 * success[i] / (success[i] + failure[i]) << endl;
}
}
return 0;
}
继续加油。
来源:CSDN
作者:Intelligence1028
链接:https://blog.csdn.net/Intelligence1028/article/details/104443574