组队选拔赛01 ---- trener
2015-07-18 23:47
232 查看
Problem Description
Mirko has been moving up in the world of basketball, starting as a mere spectator, mastering snack salesmanship, finally reach the coveted position of the national team coach. He is now facing a difficulttask: selecting the five primary players for the upcoming match against Tajikistan.Since Mirko is incredibly lazy, he doesn’t bother remembering players’ names, let alone their actual skills. That’s why he has settled on selecting five players who share the same first letter of their surnames, so that he can remember them more easily. If there are no five players sharing the first letter of their surnames, Mirko will simply forfeit the game!
In order to obtain insight into possibilities for his team, Mirko wants to know all the different letters that his primary team’s surnames may begin with.
Input
There are multiple test cases. Please process till EOF.The first line of input contains the positive integer N (1 ≤ N ≤ 150), the number of players that Mirko has available.
Each of the following N lines contains one word (at most 30 characters long, consisting only of lowercase English letters), a surname of one of the players.
Output
If there are no five players that Mirko can select matching his criteria, output a single line containing the word “PREDAJA” (without quotes). Otherwise, output all possible first letters of representation player surnames, sorted lexicographically, in a single line with no spaces.Sample Input
18babic
keksic
boric
bukic
sarmic
balic
kruzic
hrenovkic
beslic
boksic
krafnic
pecivic
klavirkovic
kukumaric
sunkic
kolacic
kovacic
prijestolonasljednikovic
6
michael
jordan
lebron
james
kobe
bryant
Sample Output
bkPREDAJA
解题思路
题意就是 找出名字首字母相同且人数大等于5的 字母.用map的话可以映射字母和当前的人数,再判断是否大等于5即可.
参考代码
#include <cstdio> #include <map> using namespace std; int main() { int n; char name[35]; while (~scanf("%d", &n)){ map<char,int> m; while (n--){ scanf("%s", name); m[name[0]]++; } bool find = false; for (int i = 'a';i <= 'z';i++) if (m[i] >= 5){ printf("%c",i); find = true; } if (!find) printf("PREDAJA"); printf("\n"); } return 0; }
相关文章推荐
- Android 开发有哪些新技术出现?
- 协同函数的脚本编写
- HDU 2639 Bone Collector II(01背包 求第k大)
- Java基础学习之内部类
- python标准库:collections和heapq模块
- python模块 - collections模块
- LeetCode Single Number (找不不重复元素)
- 存储学习笔记第一节
- C++ Primer快速入门之五:实用的模板库
- winform中的dateTimePicker控件怎么设置它的默认值为空
- 《JavaScript设计模式与开发实践》读书笔记之模板方法模式
- linux下Oracle自启动配置及启动脚本 12c 测试通过
- linux下helloworld的简单编译过程
- 二维数组的选择排序
- PHP,C++,Mysql
- 2015071805 - 所有的都是体验
- [BZOJ1036][ZJOI2008]树的统计Count
- 2015.07.18总结
- 生命不息,奋斗不止
- python基础