33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <stdio.h>
#include <string>
#include <ctype.h>
using namespace std;
int main() {
char stra[201];
while(gets(stra)){
string a = stra;
char strb[201];
char strc[201];
gets(strb); gets(strc);
string b = strb; string c = strc;
int startpos = 0;
int pos = a.find(b, startpos);
while(pos != string::npos) {
a.erase(pos, b.size());
a.insert(pos, c);
startpos = pos + c.size();
pos = a.find(b, startpos);
}
cout << a << endl;
}
return 0;
}
#include <iostream>
#include <stdio.h>
#include <string>
#include <ctype.h>
using namespace std;
int main() {
char stra[201];
while(gets(stra)){
string a = stra;
char strb[201];
char strc[201];
gets(strb); gets(strc);
string b = strb; string c = strc;
int pos = a.find(b, 0);
while(pos != string::npos) {
if ((a[pos-1] == ' ' || pos == 0) && (a[pos + b.size()] == ' ') || a[pos + b.size()] == 0){
a.erase(pos, b.size());
a.insert(pos, c);
pos = a.find(b, pos);
}
else{
pos = a.find(b, pos + b.size());
}
}
cout << a << endl;
}
return 0;
}
if ((a[pos-1] == ' ' || pos == 0) && (a[pos + b.size()] == ' ') || a[pos + b.size()] == 0){
这一行没明白最后等于0的意义
有人能指点一下吗?