题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/type/7
文章目录
L1-1 PTA使我精神焕发 (5分)
#include <iostream>
using namespace std;
int main(void)
{
cout << "PTA shi3 wo3 jing1 shen2 huan4 fa1 !" << endl;
return 0;
}
L1-2 6翻了 (15分)
需要额外考虑连续的6在末尾的情况
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string s;
int cnt = 0;
getline(cin, s);
for (int i = 0; i < s.size(); i++){
if (s[i] == '6')
cnt++;
if (s[i] != '6' || i == s.size() - 1){
//如果当前不是6或者是最后一个字符
if (cnt <= 3){
for (int j = 0; j < cnt; j++)
cout << "6";
}
else if (cnt > 3 && cnt <= 9)
cout << "9";
else if (cnt > 9)
cout << "27";
cnt = 0;
if (i != s.size() - 1)//当前不是最后一个字符
cout << s[i];
else if (i == s.size() - 1 && s[i] != '6')//当前是最后一个字符并且不是6
cout << s[i];
}
}
cout << endl;
return 0;
}
L1-3 敲笨钟 (20分)
灵活使用find函数
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(void)
{