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 }

 

 


免責聲明!

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



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