描述

编写一个程序实现将字符串中的所有"you"替换成"we"

输入
输入包含多行数据

每行数据是一个字符串,长度不超过1000 
数据以EOF结束

输出
对于输入的每一行,输出替换后的字符串
样例输入
you are what you do
样例输出
    we are what we do
STL string 练手题:
熟悉 find 函数,以及 replace 函数
//Asimple
#include <iostream>
#include <string> using namespace std;
string str, s1="you", s2="we"; int main()
{
int pos;
while( getline(cin,str) )
{
pos = str.find(s1,0);
while( pos != string::npos )
{
str.replace(pos,3,s2);
pos = str.find(s1,pos+1);
}
cout << str << endl ;
}
return 0;
}

ACM题目————STL练习之字符串替换的更多相关文章

  1. ACM题目————STL练习之求次数

    题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...

  2. ACM题目————STL练习之Ananagrams

    Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...

  3. ACM题目————STL练习之众数问题

    描述 所谓众数,就是对于给定的含有N个元素的多重集合,每个元素在S中出现次数最多的成为该元素的重数, 多重集合S重的重数最大的元素成为众数.例如:S={1,2,2,2,3,5},则多重集S的众数是2, ...

  4. ACM题目————STL + 全排列

    今天碰到一个函数,感觉挺好用的,全排列函数 next_permutation! 求全排列的函数,基本上与自己写的DFS时间复杂度差不多,毕竟是标准库.(2018-1-4 添加) 话不多说,直接上题. ...

  5. ACM题目————STL练习之 懒省事的小明(优先队列)

    描述 小明很想吃果子,正好果园果子熟了.在果园里,小明已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.小明决定把所有的果子合成一堆. 因为小明比较懒,为了省力气,小明开始想点子了: 每一 ...

  6. NYOJ 113 字符串替换(C++STL解法)

    字符串替换 时间限制:3000 ms  |            内存限制:65535 KB 难度:2 描写叙述 编写一个程序实现将字符串中的全部"you"替换成"we& ...

  7. ACM 字符串替换

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

  8. codewars.DNA题目几种解法分析(字符串替换)

    题干: 意思就是字符串替换,"A"与"C"配对,"T"与"G"配对,DNA不为空. 解法一:我的解法,用for循环遍历字 ...

  9. 【ACM】poj_3981_字符串替换_201307271019

    字符串替换Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 8447  Accepted: 3988 Description 编写 ...

随机推荐

  1. 多配置文件部署mysql单机多实例

    1.安装gcc-c++.ncurses依赖包 # yum install gcc-c++ ncurses-devel 2.安装cmake,用来编译mysql # tar -xvf cmake-3.2. ...

  2. PAT 解题报告 1013. Battle Over Cities (25)

    1013. Battle Over Cities (25) t is vitally important to have all the cities connected by highways in ...

  3. Summary: Merge Sort of Array && 求逆序对

    常用算法(后面有inplace版本): package ArrayMergeSort; import java.util.Arrays; public class Solution { public ...

  4. 算法提高 c++_ch02_01

    http://lx.lanqiao.org/problem.page?gpid=T237  算法提高 c++_ch02_01   时间限制:1.0s   内存限制:512.0MB      编写一个程 ...

  5. ACM常用算法及练习(1)

    ACM常用算法及练习 第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码,因为太常用,所以要练到写时不用想,10-15分钟内打完,甚至关掉显示器都可以把程序打出来. 1.最短 ...

  6. HDU 4899 Hero meet devil(状压DP)(2014 Multi-University Training Contest 4)

    Problem Description There is an old country and the king fell in love with a devil. The devil always ...

  7. 同时启动多个Tomcat

    一,修改配置文件server.xml的端口 C:\apache-tomcat-5.5.23-1\conf\server.xml用记事本什么的打开修改3个地方   第一: <Server port ...

  8. oracle的索引维护

    索引重建 Alter index idx_name rebuild partition index_partition_name [online nologging] 需要对每个分区索引做rebuil ...

  9. PAT乙级 1025. 反转链表 (25)

    1025. 反转链表 (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一个常数K以及一个单链表L,请 ...

  10. 使用sysprep克隆虚拟机

    1.虚拟机安装windows2008 x64 r2 2.安装完毕后,运行”c:\windows\system32\sysprep\sysprep.exe” 3.选择”进入系统全新体验(OOBE),勾选 ...