letters
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 34, Accepted users: 32
Problem 12316 : No special judgement
Problem description
Mr Sythe is teaching an ESOL class about repeated letters in English words. As an exercise,he gets his students to replace all the repeated letters in a word with symbols.
The symbols used are as follows:
* is used to replace the first repeated letter (the first letter encountered which has occurred before)
? for the second repeated letter
/ for the third repeated letter
+ for the fourth repeated letter
! for the fifth repeated letter.
No word that Mr Sythe uses has more than 5 repeated letters.
So, for example, the word Reindeer would become Reind**? because e is repeated twice and r is repeated once. The repeated e comes before the repeated r, hence the allocation of * to e and ? to r. Note that the first letter in the word is an upper case R, but this is treated as the same letter as the lower case r. 

Input
In this problem, you will write a program to help Mr Sythe mark the exercise by giving him a list of correct answers. Input will consist of a list of words, one per line. Each word begins with an upper case letter and contains no more than 10 letters. The last line contains just a # - do not process this line.

Output
Output will be one word for each line of input each on a separate line. The output word must be the input word with repeated letters replaced as indicated by Mr Sythe's rules.

Sample Input
Reindeer
Bubbles
Occurrence
#
Sample Output
Reind**?
Bu**les
Oc*ur?en*/
Problem Source
NewZealand2011 

 

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char s[11],a[5]={'*','?','/','+','!'};
 8     int i,j,len,k,l;
 9     while(cin>>s&&strcmp(s,"#"))
10     {
11         len=strlen(s);
12         k=0;
13         for(i=1;i<len;i++)    
14         for(j=i-1;j>=0;j--)
15         {
16         if(isalpha(s[i]))
17         {
18             if(s[j]==s[i]||s[j]==s[i]+'A'-'a'||s[j]==s[i]+'a'-'A')
19             {
20                 s[i]=a[k++];
21             for(l=i+1;l<len;l++)
22             if(s[j]==s[l]||s[j]==s[l]+'A'-'a'||s[j]==s[l]+'a'-'A')
23                 s[l]=s[i];
24             }
25         }
26         }
27         for(i=0;i<len;i++)
28         cout<<s[i];
29         cout<<"\n";
30     }
31     return 0;
32 }
posted on 2012-07-19 21:17  黑色的铅笔  阅读(164)  评论(0编辑  收藏  举报