题解 CF493A 【Vasya and Football】

这题其实就是模拟

题目大意:已知有两个球队home和away,现在给出一些足球运动员被黄牌或红牌警告的时间,求每个队员第一次被红牌警告的时间。(2张黄牌会自动变成1张红牌)

已经描述的很清楚了。

具体看代码吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<bits/stdc++.h>
using namespace std;
const int max_n=111;
int n,f[2][max_n];
string a[2];
int main(){
cin>>a[0]>>a[1]>>n;//读入2个队的名字和总被罚次数
while(n--){
int t,num,q,c;
char c1,c2;
cin>>t>>c1>>num>>c2;//读入被罚的队、队员编号、红牌还是黄牌和时间
if(c1=='h')q=0;
else q=1;//q=0->home队
if(c2=='y')c=1;
else c=2;//保证一张红牌抵两张红牌
if(f[q][num]<2){//如果之前没被罚下去
f[q][num]+=c;//加上本次的惩罚
if(f[q][num]>=2)cout<<a[q]<<" "<<num<<" "<<t<<endl;//如果本次被罚到红牌了,再见
}
}
return 0;
}