NYOJ113 字符串替换

原题链接

string.find(); 和 string.replace();的用法。

#include <iostream>
#include <string>
using namespace std;

int main(){
	string str;
	int p;
	while(getline(cin, str)){
		p = str.find("you");
		while(p != string::npos){
			str.replace(p, 3, "we");
			p = str.find("you", p + 1);
		}
		cout << str << endl;
	}
	return 0;
}


posted on 2014-02-20 10:02  长木Qiu  阅读(122)  评论(0编辑  收藏  举报