题目描述
学校设计了很多的标语,但是中间很多地方都把No_smoking 写成了Ban_smoking。 请你找到这些错误并将他们替换成正确的结果。保证每个标语中至多包含一个Ban_smoking 。
输入
输入第一行为N表示总共的标语数量。之后的N行每行有一个待处理的标语。每个标语中不带有任何的空格。
输出
输出为N行,为经过处理后的所有的标语。
输出顺序与输入时保持一致。
样例输入
4 Ban_smoking_is_good Yes,We_are_good.Ban_smoking I_ban_smoking I_love_you,Ban_pig
样例输出
No_smoking_is_good Yes,We_are_good.No_smoking I_ban_smoking I_love_you,Ban_pig
#include
using namespace std;
void findStr(string str);
void replace (string str);
int main() {
char str[50][100];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", &str[i]);
}
for (int i = 0; i < n; i++) {
replace(str[i]);
}
return 0;
}
void findStr(string str) {
cout << str.find("Ban_smoking") << endl;
}
void replace (string str) {
int pos;
pos = str.find("Ban_smoking");
while (pos != -1) {
str.replace(pos, string("Ban_smoking").length(), "No_smoking");
pos = str.find("Ban_smoking");
}
cout << str << endl;
}