113-字符串替换

内存限制:64MB 时间限制:3000ms 特判: No
通过数:171 提交数:388 难度:2

题目描述:

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

输入描述:

输入包含多行数据 

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

输出描述:

对于输入的每一行,输出替换后的字符串

样例输入:

复制

you are what you do

样例输出:

we are what we do

用find()找you的位置,然后用replace替换。
C++代码:
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
while(getline(cin,s)){
string s1 = "you";
string s2 = "we";
int ans = s.find(s1,);//从下标为0开始寻找。
while(ans>=){
s.replace(ans,,s2); //replace(a,b,c),a指的是"you"的位置,b指的是要替换的长度,c指的是"we"。
ans = s.find(s1,ans+);
}
cout<<s<<endl;
}
return ;
}

(replace find)nyoj113-字符串替换的更多相关文章

  1. StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?

    StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...

  2. JS字符串替换函数:Replace(“字符串1″, “字符串2″),

    JS字符串替换函数:Replace(“字符串1″, “字符串2″), 1.我们都知道JS中字符串替换函数是Replace(“字符串1″, “字符串2″),但是这个函数只能将第一次出现的字符串1替换掉, ...

  3. sql server 字符串替换函数REPLACE

    sql server 字符串替换函数REPLACE函数的使用 <pre name="code" class="sql">--参数1:需要替换字符的母 ...

  4. Python3字符串替换replace(),translate(),re.sub()

    Python3的字符串替换,这里总结了三个函数,replace()和translate()和re.sub() replace() replace() 方法把字符串中的 old(旧字符串) 替换成 ne ...

  5. nyoj 113 字符串替换 (string中替换函数replace()和查找函数find())

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

  6. string类自定义字符串替换函数replace

    #include <iostream> #include <string> using namespace std; /* *  函数功能:将string字符串中的某些字符替换 ...

  7. 字符串替换replace方法

    字符串替换replace方法: http://www.w3school.com.cn/jsref/jsref_replace.asp http://www.cnblogs.com/skywang/ar ...

  8. python 字符串替换功能 string.replace()可以用正则表达式,更优雅

    说起来不怕人笑话,我今天才发现,python 中的字符串替换操作,也就是 string.replace() 是可以用正则表达式的. 之前,我的代码写法如下,粗笨: 自从发现了正则表达式也生效后,代码变 ...

  9. C#不区分大小写的字符串替换(Replace)函数

    在.NET中,不调用C++/CLI,进行字符串替换有好几种方法: 1.最常用的,就是String实例.Replace(),但这个不能忽略大小写. 2.System.Text.Regex(Regular ...

  10. oracle学习笔记:字符串替换 replace、regexp_replace、translate函数

    1.replace 函数 语法:replace(char, search_string, replacement_string) --针对字符串替换 功能: ​ 将char中的字符串替换. ​ 当re ...

随机推荐

  1. array_merge

    1.array_merge 中有两个参数:将两个关联数组合并为一个数组 <?php $a1=array("a"=>"red","b&quo ...

  2. DFI LP DK P45 T2RS PLUS BIOS SETTING

    standard cmos features date (mm:dd:yy) mon,oct 11 2016 time (hh:mm:ss) 10 : 10 : 26 ide channel 0 sa ...

  3. aop通配符语法

    *.表示通配包名  *. == com. com.rl.ecps.service == *.*.*.*. ..表示 通配任何包及其子包   例如 com.. ==com. *.*.*. com.rl. ...

  4. Tcp协议的keepalive功能

    L:128

  5. sklearn训练感知器用iris数据集

    简化版代码 from sklearn import datasets import numpy as np #获取data和类标 iris = datasets.load_iris() X = iri ...

  6. GitHub大佬:供计算机学习鉴黄功能的图片数据库

    ps:学无止境 想要构建一套鉴黄系统,必须有大量的真实图片供计算机进行学习,以便于区分开正常图片和黄色图片. 近期有位加拿大程序员在Github上传了图片列表,里面包含了大量图片地址可以供计算机进行学 ...

  7. CH2101 可达性统计(算竞进阶习题)

    拓扑排序+状态压缩 考虑每一个点能够到达的所有点都是与该店相邻的点的后继节点,可知: 令f[u]表示u点可到达的节点个数,f[u]={u}与f[v](u, v)的并集 于是可以利用状态压缩,能够到达的 ...

  8. python打印log重复问题

    本博客转载于:http://www.cnblogs.com/huang-yc/p/9209096.html,写得真不错 浅析python日志重复输出问题 目录 问题起源: 问题解析 解决办法 1.改名 ...

  9. 如何简单实现接口自动化测试(基于 python) 原博主地址https://blog.csdn.net/gitchat/article/details/77849725

    如何简单实现接口自动化测试(基于 python) 2017年09月05日 11:52:25 阅读数:9904 GitChat 作者:饿了么技术社区 原文:如何简单实现接口自动化测试(基于 python ...

  10. jquery-Ajax请求用例码

    $.ajax({                    type:"post",                    url: 'domain’,                 ...