乐逍遥xwl

导航

L1-058 6翻了

666.JPG

“666”是一种网络用语,大概是表示某人很厉害、我们很佩服的意思。最近又衍生出另一个数字“9”,意思是“6翻了”,实在太厉害的意思。如果你以为这就是厉害的最高境界,那就错啦 —— 目前的最高境界是数字“27”,因为这是 3 个 “9”!

本题就请你编写程序,将那些过时的、只会用一连串“6666……6”表达仰慕的句子,翻译成最新的高级表达。

输入格式:

输入在一行中给出一句话,即一个非空字符串,由不超过 1000 个英文字母、数字和空格组成,以回车结束。

输出格式:

从左到右扫描输入的句子:如果句子中有超过 3 个连续的 6,则将这串连续的 6 替换成 9;但如果有超过 9 个连续的 6,则将这串连续的 6 替换成 27。其他内容不受影响,原样输出。

输入样例:

it is so 666 really 6666 what else can I say 6666666666

输出样例:

it is so 666 really 9 what else can I say 27
 
思路:直接把字符串先用getline读取,再遍历一遍字符串找6......
 
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<map>
 6 #include<set>
 7 #include<vector>
 8 using namespace std;
 9 #define ll long long 
10 #define dd cout<<endl
11 const int inf=99999999;
12 const int mod=1e9+7;
13 const int maxn=1e5+7;
14 int main()
15 {
16     string str;
17     getline(cin,str);
18     string temp="";
19     int cnt=0;
20     for(int i=0;i<str.size();i++)
21     {
22         if(str[i]=='6')
23             cnt++;
24         else if(str[i]!='6')
25         {
26             if(cnt==0)
27                 temp+=str[i];
28             else if(cnt<=3)
29             {
30                 for(int j=0;j<cnt;j++)
31                     temp+='6';
32                 temp+=str[i];
33                 cnt=0;
34             }
35             else if(cnt>3&&cnt<=9)
36             {
37                 cnt=0;
38                 temp+='9';
39                 temp+=str[i];
40             }
41             else if(cnt>9)
42             {
43                 cnt=0;
44                 temp+="27";
45                 temp+=str[i];
46             }
47         }
48     }
49     if(cnt<=3)
50     {
51         for(int j=0;j<cnt;j++)
52             temp+='6';
53         cnt=0;
54     }
55     else if(cnt>3&&cnt<=9)
56     {
57         cnt=0;
58         temp+='9';
59     }
60     else if(cnt>9)
61     {
62         cnt=0;
63         temp+="27";
64     }
65     cout<<temp<<endl;
66     return 0;
67 }

 

 

posted on 2019-04-02 12:52  乐逍遥xwl  阅读(986)  评论(0编辑  收藏  举报