阅读1007 返回首页    go 技术社区[云栖]


字符串替换

字符串替换

时间限制:3000 ms  |  内存限制:65535 KB
难度:2
描述
编写一个程序实现将字符串中的所有"you"替换成"we"
输入
输入包含多行数据

每行数据是一个字符串,长度不超过1000
数据以EOF结束
输出
对于输入的每一行,输出替换后的字符串
样例输入
you are what you do
样例输出
we are what we do
01.#include <iostream>
02.#include <string>
03.#include <vector>
04.using namespace std;
05. 
06.int main()
07.{
08.string exp;
09.while (getline(cin, exp))
10.{
11.int len = exp.size();
12.for (int i = 0; i < len-2; i++)
13.{
14.if (exp[i] == 'y' && exp[i+1] == 'o' && exp[i+2] == 'u')
15.{
16.exp[i] = 'w';
17.exp[i+1] = 'e';
18.exp.erase(exp.begin()+ i + 2);
19.}
20.}
21.cout << exp << endl;
22. 
23.}
24. 
25.return 0;
26.}

最后更新:2017-04-03 05:40:23

  上一篇:go Oracle中的nvl函数
  下一篇:go J2EE中getParameter与getAttribute以及EL表达式${requestScope}和${param[]}