閱讀1007 返回首頁    go 阿裏雲 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[]}