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 }
浙公网安备 33010602011771号