Codeforces Round #281 (Div. 2) A - Vasya and Football
来源:互联网 发布:戴比尔斯钻石骗局 知乎 编辑:程序博客网 时间:2024/05/16 06:48
这是我第一次在csdn上写博,由于今后读研的需要,以及我的研究生导师给我布置了大量Codeforces练习任务,我不得不重拾学得很烂的C++,本着记录研前学习的苦逼历程与收获,以及发扬极客的分享精神,我决定将学习的东西开始在博客上做记录总结,以后可能还会记录一些关于OpenCV在iOS上的应用,本人非大神,重在交流学习。
Codeforces Round #281 (Div. 2) A - Vasya and Football,题目如下:
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.
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.
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).
MCCSKA928 a 3 y62 h 25 y66 h 42 y70 h 25 y77 a 4 y79 a 25 y82 h 42 r89 h 16 y90 a 13 r
MC 25 70MC 42 82CSKA 13 90
输入格式:主队名称
客队名称
本场总犯规记录数
犯规时间 主/客队 球员号 黄/红牌
。。。
输出格式:主/客队 球员号 犯规时间
。。。
当清楚了输入输出的内容之后,我们大概知道这道题目的关键就是查找关键信息,最后再以另一种形式输出,为了方便信息的输入,我建立了一个records的结构体来存储犯规信息,同时也为输出格式建立了结构体outputline:
struct records { int time; char team; int playerNumber; char colorOfcard;};struct outputline { string team; int playerNumber; int time;};
为了减少循环遍历的次数,我选择输入一条记录便对记录进行判断,并且将判断后可能的输出存入vector数组中,于是,这里就出现了一个问题,我起初像书上那样将结构体声明在主函数内部,并且声明了一个outputline类型(输出的格式)的vector,在自己电脑上编译时没有问题,但是提交到codeforces上就出现了编译错误,错误如下:
Can't compile file:program.cpp: In function 'int main()':program.cpp:25:27: error: template argument for 'template<class _Alloc> class std::allocator' uses local type 'main()::outputline'program.cpp:25:27: error: trying to instantiate 'template<class _Alloc> class std::allocator'program.cpp:25:27: error: template argument 2 is invalidprogram.cpp:25:41: error: invalid type in declaration before ';' tokenprogram.cpp:37:26: error: request for member 'push_back' in 'outputsline1', which is of non-class type 'int'program.cpp:51:30: error: request for member 'push_back' in 'outputsline1', which is of non-class type 'int'program.cpp:55:38: error: request for member 'size' in 'outputsline1', which is of non-class type 'int'program.cpp:56:31: error: invalid types 'int[int]' for array subscriptprogram.cpp:57:31: error: invalid types 'int[int]' for array subscriptprogram.cpp:58:31: error: invalid types 'int[int]' for array subscript
查了一下午才发现是因为自己将结构体声明在了main函数里,而按C98标准来说,局部类不是外部链接属性的,不可以成为模板的参数。所以将结构体声明在mian函数之外即可,同样,deque的参数也不可以为局部类。完整程序如下:
- Codeforces Round #281 (Div. 2) A. Vasya and Football
- Codeforces Round #281 (Div. 2) A - Vasya and Football
- #281 (div.2) A.Vasya and football
- Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- Codeforces Round #262 (Div. 2) A. Vasya and Socks
- Codeforces Round #281 (Div. 2)-D. Vasya and Chess
- Codeforces 493A. Vasya and Football 水
- Codeforces 493A Vasya and Football(水)
- CodeForces-493A.Vasya and Football
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball&D. Vasya and Chess
- Codeforces Round #206 (Div. 1) A. Vasya and Robot
- A. Vasya and Football
- A Vasya and Football
- A. Vasya and Football
- Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)
- 【Codeforces Round 262 (Div 2)A】【水题】Vasya and Socks 妈妈买袜子 最多穿几天
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- Codeforces Round #206 (Div. 2) B. Vasya and Public Transport
- neutron分配浮动IP(floating ip)的方法
- CXF在AIX+Weblogic环境下出现包冲突问题
- 不同数据库分页总结
- jsp if else c标签 总结
- UVA - 1452 (jump 约瑟夫变形,求后三位数)
- Codeforces Round #281 (Div. 2) A - Vasya and Football
- phantomjs服务器linux32位系统安装使用记录
- windows远程桌面超出最大连接数的解决方法
- Redis脚本
- 通用分类标准实施
- 第17周 项目6-学生成绩统计
- Longest Common Prefix(最长公共前缀)
- 一起学习HTTP协议
- NYOJ 房间安排 168