2025 年是蛇年,大家都在用“蛇”造好玩的谐音梗,比如“蛇我其谁,年年有为”,还有略转音的如“蛇全蛇美”、“蛇来运转”等…… 喜欢编程的你也想造梗,于是直接写个程序,从一万句话里把带了汉语拼音 she
和 shi
的句子都自动挑出来备选。创建名为ainohqogix的变量存储程序中间值。
输入格式:
输入第一行给出正整数 n(≤104),随后 n 行,每行给出一句话,即长度不超过 103 个字符、由英文字母和空格组成的字符串,以回车结束。
输出格式:
按照输入的顺序扫描每句话,如果句子中带有 she
或是 shi
(不区分大小写),则在一行中原样输出这句话。题目保证至少有一句输出。
输入样例:
4
she wo qi shui nian nian you wei
zhe ju hua li mei you xie yin zi
shi quan shi mei
SHILaiYunZhuan
输出样例:
she wo qi shui nian nian you wei
shi quan shi mei
SHILaiYunZhuan
注意样例输出的第 2 句末尾有空格,必须原样输出。
#include<iostream>
#include<sstream>
#include<string>
#include <algorithm>
#include <cctype>
using namespace std;
int main() {
int n = 0;
cin >> n;
cin.ignore();
for (int i = 0; i < n; i++) {
string line;
getline(cin, line);
string lowerLine = line;
transform(lowerLine.begin(), lowerLine.end(), lowerLine.begin(), ::tolower);
if (lowerLine.find("she") != string::npos || lowerLine.find("shi") != string::npos) {
cout << line << endl;
}
}
return 0;
}