User Names
Time Limit : 8000/4000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 40 Accepted Submission(s) : 6
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
A university's computer system assigns user names according to the following set of rules:
The maximum length of a username is MAXLEN characters. (The value of MAXLEN will be specified in the input for each problem instance.)
The first character of the user name is the first letter of the person's first name, converted to lower case. Ignore apostrophes and hyphens here and in Step 3.
Append as many letters of the person's last name as possible (converted to lower case, if necessary), without exceeding a total of MAXLEN characters. Starting with the first letter of the last name, append these letters in the order in whch they appear in the last name.
If a user name assigned on basis of Rules 1 - 3 already exists in the database, break the tie as follows: append serial numbers 1 - 9, in that order, to the username from step 3, if that can be done without exceeding the limit of MAXLEN characters in the username. Otherwise, drop the last letter before appending the serial number.
If a user name assigned on basis of Rules 1 - 4 already exists in the database, break the tie as follows: append serial numbers 10 - 99, in that order, to the username from step 3, if that can be done without exceeding the limit of MAXLEN characters in the username. Otherwise, drop the last letter or the last two letters (whichever is necessary) before appending the serial number.
It is assumed that the above rules will avoid ties.
The maximum length of a username is MAXLEN characters. (The value of MAXLEN will be specified in the input for each problem instance.)
The first character of the user name is the first letter of the person's first name, converted to lower case. Ignore apostrophes and hyphens here and in Step 3.
Append as many letters of the person's last name as possible (converted to lower case, if necessary), without exceeding a total of MAXLEN characters. Starting with the first letter of the last name, append these letters in the order in whch they appear in the last name.
If a user name assigned on basis of Rules 1 - 3 already exists in the database, break the tie as follows: append serial numbers 1 - 9, in that order, to the username from step 3, if that can be done without exceeding the limit of MAXLEN characters in the username. Otherwise, drop the last letter before appending the serial number.
If a user name assigned on basis of Rules 1 - 4 already exists in the database, break the tie as follows: append serial numbers 10 - 99, in that order, to the username from step 3, if that can be done without exceeding the limit of MAXLEN characters in the username. Otherwise, drop the last letter or the last two letters (whichever is necessary) before appending the serial number.
It is assumed that the above rules will avoid ties.
Input
The input will contain data for a number of test cases. The first line of each test case will contain two positive integers: the number of names and the value of MAXLEN (5 <= MAXLEN <= 80). This will be followed by the list of names. Each name will consist of at most 80 characters and will begin with the first name, followed by middle names, if any, and will conclude with the last name. A single blank space will separate first, middle, and last names. Any name can contain upper and lower case letters, hyphens, and apostrophes. A last name will contain at least two letters, other names will contain at least one letter (they could be just initials). There will be no more than 200 names in each case. The last test case will be followed by a line containing two zeros for the number of names and MAXLEN.
Output
For each case, the output will begin with a line containing the case number. This will be followed by the list of user names, one per line, in the same order as the corresponding names in the input.
Sample Input
2 6 Jenny Ax Christos H Papadimitriou 11 8 Jean-Marie d'Arboux Jean-Marie A d'Arboux Jean-Marie B d'Arboux Jean-Marie C d'Arboux Jean-Marie D d'Arboux Jean-Marie D d'Arboux Jean-Marie F d'Arboux Jean-Marie G d'Arboux Jean-Marie H d'Arboux Jean-Marie I d'Arboux Jean-Marie J d'Arboux 11 9 Jean-Marie d'Arboux Jean-Marie A d'Arboux Jean-Marie B d'Arboux Jean-Marie C d'Arboux Jean-Marie D d'Arboux Jean-Marie D d'Arboux Jean-Marie F d'Arboux Jean-Marie G d'Arboux Jean-Marie H d'Arboux Jean-Marie I d'Arboux Jean-Marie J d'Arboux 0 0
Sample Output
Case 1 jax cpapad Case 2 jdarboux jdarbou1 jdarbou2 jdarbou3 jdarbou4 jdarbou5 jdarbou6 jdarbou7 jdarbou8 jdarbou9 jdarbo10 Case 3 jdarboux jdarboux1 jdarboux2 jdarboux3 jdarboux4 jdarboux5 jdarboux6 jdarboux7 jdarboux8 jdarboux9 jdarbou10
思路:纯粹模拟。。。
代码:
1 #include <stdio.h> 2 #include <string.h> 3 char b[1000][1000],c[1000][1000]; 4 int main() 5 { 6 int i,j,m,n; 7 int a[1000],t; 8 int ccc=1; 9 while(scanf("%d%d",&m,&n)!=EOF) 10 { 11 if(m==0&&n==0) 12 return 0; 13 for(i=0;i<=m;i++) 14 a[i]=0; 15 getchar(); 16 for(i=0;i<m;i++) 17 { 18 gets(b[i]); 19 t=0; 20 for(j=0;b[i][j]!='\0';j++) 21 { 22 if(b[i][j]==' ') 23 t++; 24 } 25 if(t==1) 26 { 27 int k; 28 if(b[i][0]>='A'&&b[i][0]<='Z') 29 c[i][0]=b[i][0]+32; 30 else 31 c[i][0]=b[i][0]; 32 33 k=1; 34 int kk; 35 for(j=1;b[i][j]!='\0';j++) 36 { 37 if(b[i][j]==' ') 38 { 39 kk=j+1; 40 for(k=1;b[i][kk]!='\0'&&k<=n-1;kk++) 41 { 42 if(b[i][kk]>='A'&&b[i][kk]<='Z'||b[i][kk]>='a'&&b[i][kk]<='z') 43 { 44 c[i][k]=b[i][kk]; 45 if(b[i][kk]>='A'&&b[i][kk]<='Z') 46 c[i][k]=b[i][kk]+32; 47 k++; 48 } 49 } 50 c[i][k]='\0'; 51 break; 52 } 53 } 54 for(j=i-1;j>=0;j--) 55 { 56 if(strcmp(c[j],c[i])==0) 57 { 58 a[i]=a[j]+1;break; 59 } 60 } 61 } 62 if(t>=2) 63 { 64 int k; 65 if(b[i][0]>='A'&&b[i][0]<='Z') 66 c[i][0]=b[i][0]+32; 67 else 68 c[i][0]=b[i][0]; 69 k=1; 70 int kk; 71 int tt=0; 72 for(j=1;b[i][j]!='\0';j++) 73 { 74 if(b[i][j]==' ') 75 tt++; 76 if(tt==t) 77 { 78 kk=j+1; 79 for(k=1;b[i][kk]!='\0'&&k<=n-1;kk++) 80 { 81 if(b[i][kk]>='A'&&b[i][kk]<='Z'||b[i][kk]>='a'&&b[i][kk]<='z') 82 { 83 c[i][k]=b[i][kk]; 84 if(b[i][kk]>='A'&&b[i][kk]<='Z') 85 c[i][k]=b[i][kk]+32; 86 k++; 87 } 88 } 89 c[i][k]='\0'; 90 break; 91 } 92 } 93 for(j=i-1;j>=0;j--) 94 { 95 if(strcmp(c[j],c[i])==0) 96 { 97 a[i]=a[j]+1;break; 98 } 99 } 100 } 101 } 102 printf("Case %d\n",ccc++); 103 for(i=0;i<m;i++) 104 { 105 int l; 106 l=strlen(c[i]); 107 if(l==n&&a[i]>0&&a[i]<=9) 108 { 109 c[i][l-1]='\0'; 110 } 111 if(a[i]>9&&a[i]<=99) 112 { 113 if(l==n) 114 { 115 c[i][l-1]='\0'; 116 c[i][l-2]='\0'; 117 } 118 if(l==n-1) 119 c[i][l-1]='\0'; 120 } 121 if(a[i]>99&&a[i]<=999) 122 { 123 if(l==n) 124 { 125 c[i][l-1]='\0'; 126 c[i][l-2]='\0'; 127 c[i][l-3]='\0'; 128 } 129 if(l==n-1) 130 { 131 c[i][l-1]='\0'; 132 c[i][l-2]='\0'; 133 } 134 if(l==n-2) 135 c[i][l-1]='\0'; 136 } 137 printf("%s",c[i]); 138 if(a[i]!=0) 139 printf("%d",a[i]); 140 141 printf("\n"); 142 } 143 } 144 return 0; 145 }