• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Warm up 3 [I] Eligibility

为何你这么叼!

[I] Eligibility

 

Regional Contest Director Osama Ismail knows that an individual cannot participate in the regional contest more than 5 times. Given a list of contestant names and the previous years they participated in, print which contestant is eligible. 


Input Specification
The first line of the input contains a single integer T representing the number of the test cases The first line of each test case contains a single integer N N lines follow in this test case each having the format "Name Year" denoting that contestant Name participated in a regional contest in year Year 
T ≤ 100 0 ≤ N ≤ 500 Name is sequence of lowercase English letters, spaces and contains up to 20 characters 1970 ≤ Year ≤ 2070 
Note that since he collected the data from multiple sources it may contain duplicate records (if a contestant X have competed in year Y, you might find multiple lines "X Y" in the same test case) 


Output Specification
For each test case, print a line containing the test case number as formatted in the sample and then for each eligible contestant print his\her name on a single line and note that you must print the names of the contestants in lexicographic order 


Sample Input
1

6

ahmed 2010

ahmed 2011

ahmed 2009

ahmed 2008

ahmed 2005

mohamed 2001

 

Sample Output
Case #1:

mohamed

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 #define maxn 555
 6 int n,m;
 7 char str[maxn][27];
 8 char s[maxn][27];
 9 int main(){
10     int t,cas=1;
11     scanf("%d",&t);
12     while(t--){
13         printf("Case #%d:\n",cas++);
14         scanf("%d",&m);
15         getchar();
16         for(int i=0;i<m;i++)gets(str[i]);
17         for(int i=0;i<m;i++)
18             for(int j=i+1;j<m;j++)
19             if(strcmp(str[i],str[j])>0){
20                 char temps[27];
21                 strcpy(temps,str[i]);
22                 strcpy(str[i],str[j]);
23                 strcpy(str[j],temps);
24             }
25         strcpy(str[m],"Why do you so diao 23333");
26         for(int i=0;i<=m;i++)strcpy(s[i],str[i]);
27         for(int i=0;i<=m;i++){n=strlen(s[i]);s[i][n-5]='\0';}
28         for(int i=0;i<m;i++){
29             int k=0;
30             while(strcmp(s[i],s[i+1])==0)
31                 if(strcmp(str[i],str[i+1])!=0)i++,k++;
32                 else i++;
33             if(k>=4)continue;
34             else puts(s[i]);
35         }
36     }
37     return 0;
38 }
View Code 2013-10-08 21:50:26 

 

posted @ 2013-10-08 21:50  HaibaraAi  阅读(111)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3