L1-058 6翻了 (15 分)
阿新 • • 發佈:2021-02-10
L1-058 6翻了 (15 分)
題目
“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
思路
遍歷判斷即可
程式碼
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e4 + 19;
const ll mod = 1e9 + 7;
char str[N];
int main()
{
int n = 0;
while((str[n] = getchar()) != '\n')
{
n++;
}
queue<char> ans;
for(int i = 0; i < n; i++)
{
if(str[i] != '6')
{
ans.push(str[i]);
continue;
}
int cnt = 1;
while(str[++i] == '6')
cnt++;
if(cnt > 9)
ans.push('2'), ans.push('7');
else if(cnt > 3)
ans.push('9');
else
{
for(int j = 0; j < cnt; j++)
ans.push('6');
}
i--;
}
while(ans.size())
{
cout << ans.front();
ans.pop();
}
cout << endl;
return 0;
}