letters

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 }

转载于:https://www.cnblogs.com/hncu1009302xudandan/archive/2012/07/19/2600002.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值