天梯---6翻了(模擬)


“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

 

第一次 13分

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <string>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 
 9 int main()
10 {
11     string str;
12     int t=1;
13     while(cin>>str)
14     {
15         if(str.find("6666666666")!=string::npos)
16         {
17             if(t)
18             {
19                 cout<<"27";
20                 t=0;
21             } 
22             else cout<<" 27";
23         }
24         else if(str.find("6666")!=string::npos)
25         {
26             if(t)
27             {
28                 cout<<"9";
29                 t=0;
30             } 
31             else cout<<" 9";
32         }
33         else 
34         {
35             if(t)
36             {
37                 cout<<str;
38                 t=0;
39             } 
40             else cout<<" "<<str;
41         }
42     }
43     return 0;
44 }

 

第二次 14分

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <string>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 
 9 int main()
10 {
11     string str;
12     getline(cin,str);
13     int i,g;
14     int len=0;
15     for(i=0;i<=str.size();i++)
16     {
17         if(str[i]=='6') len++;
18         else 
19         {
20             if(len>9) 
21             {
22                 if(str[i]) cout<<"27 ";
23                 else cout<<"27";
24             }
25             else if(len>3) 
26             {
27                 if(str[i]) cout<<"9 ";
28                 else cout<<"9";
29             }
30             else 
31             {
32                 for(g=0;g<len;g++) cout<<'6';
33                 cout<<str[i];
34             }
35             len=0;
36         }
37     }
38     return 0;
39 }

 

第三次 15分,終於AC了............

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <string>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 
 9 int main()
10 {
11     string str;
12     getline(cin,str);
13     int i,g;
14     int len=0;
15     for(i=0;i<=str.size();i++)
16     {
17         if(str[i]=='6') len++;
18         else 
19         {
20             if(len>9) 
21             {
22                 if(str[i]) cout<<"27"<<str[i];
23                 else cout<<"27";
24             }
25             else if(len>3) 
26             {
27                 if(str[i]) cout<<"9"<<str[i];
28                 else cout<<"9";
29             }
30             else 
31             {
32                 for(g=0;g<len;g++) cout<<'6';
33                 cout<<str[i];
34             }
35             len=0;
36         }
37     }
38     return 0;
39 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM