#281 (div.2) A.Vasya and football

A. Vasya and Football
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.

Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the firstmoment of time when he would receive a red card from Vasya.

Input

The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.

Next follows number n (1 ≤ n ≤ 90) — the number of fouls.

Each of the following n lines contains information about a foul in the following form:

  • first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs;
  • then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player;
  • then goes the player's number m (1 ≤ m ≤ 99);
  • then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.

The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.

Output

For each event when a player received his first red card in a chronological order print a string containing the following information:

  • The name of the team to which the player belongs;
  • the player's number in his team;
  • the minute when he received the card.

If no player received a card, then you do not need to print anything.

It is possible case that the program will not print anything to the output (if there were no red cards).

Sample test(s)
input
MC
CSKA
9
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 r
output
MC 25 70
MC 42 82
CSKA 13 90
1.题目分析:这是我第一次在CF上做题,听队友说div2的前三题都很简单,就抱着试一试的心态做了一下,结果却令我出乎意料。光A题就提交了15次(其中7次CE)真是郁闷地没话说。各种细节被Hack。其实这是很简单的一道模拟题,搜索第一次获得红牌的队员,并按时间顺序输出。可能是我一个月没敲代码了吧。在寒假训练开始前希望稍微练练手。结果竟是如此的惨淡==。看来该下功夫努力了。不过教训还是挺宝贵的,主要有以下几点:
  (1)一定要弄清楚输入,输出变量的类型,别写int写惯了,就忽略了这个
  (2)第一次知道在CF上用MS C++编译器,构造函数只能在class中使用==
  (3)这道题的思路是以“场次+编号”组成队员名称,分配一个ID,放到一个数组中,对该数组进行搜索,如果是第一次得到红牌就令mark=true,最后按照时间排序,才知道如果用构造函数,那么所有的赋值操作都要在构造函数中完成,如果有bool型成员,那么执行完构造函数会自动变成true。涨姿势了。。。

代码:
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<string>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<fstream>
using namespace std;
int n;
string s1, s2;
class team
{
public:
	int time;
	string name;
	string card;
	bool mark;
	team(string n="",int t = 0, string c = "no",bool m=false) :name(n),time(t), card(c),mark(m){}
	bool operator <(const team&rhs)
	{
		return time < rhs.time;
	}
}t[110];
vector<string>Name;
map<string, int>list;
int ID(string name)
{
	if (!list.count(name))
	{
		Name.push_back(name);
		return list[name] = Name.size() - 1;
	}
	return list[name];
}
string na(char f)
{
	if (f == 'h')return s1;
	return s2;
}

int main()
{
	cin >> s1 >> s2 >> n;
	string name;
	int time;
	string field, num, card;
	for (int i = 0; i < n; i++)
	{
		cin >> time >> field >> num >> card;
		name = field + num;
		int ind = ID(name);
		if (t[ind].card == "no")
		{
			t[ind] = team(name, time, card);
			if (card == "r")
				t[ind].mark = true;
		}
		else if (t[ind].card=="y"&&t[ind].mark==false)
		{
			t[ind] = team(name, time, card, true);
		}
	}
		int cnt = Name.size();
		sort(t, t + cnt);
		for (int i = 0; i < cnt;i++)
		if (t[i].mark)
		{
			cout << na(t[i].name[0]) << ' ' << t[i].name.substr(1) << ' ' << t[i].time;
			if (i != cnt)cout << endl;
		}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值