题意不难理解,但是一开始还是没有看清楚题目。Replace the first occurrence of the find string within the text by the replace-by string, then try to perform the same replacement again on the new text. Continue until the find string no longer occurs within the text, and then move on to the next rule.这个地方我贡献了几次TL。它的意思是替换完第n个字符串后,继续判断是否还能被这个字符串替换,否则移至下一个。

#include <iostream>
#include <cstdio>
#include <string>
using namespace std; int main()
{
//freopen("in.txt","r",stdin);
while(1)
{
int n;
scanf("%d",&n);
if(n==0)
break;
string str1[12];
string str2[12];
getchar();
for(int i=0; i<n; i++)
{
getline(cin,str1[i]);
getline(cin,str2[i]);
}
string str3;
getline(cin,str3);
for(int i=0; i<n; i++)
while(1)
{
int index=str3.find(str1[i]); //查找要替换的字符串位置,没有返回string::npos
if(index==string::npos)
break;
str3=str3.replace(index,str1[i].length(),str2[i]); //replace函数直接替换,或者用erase和insert也行
//str3.erase(index,str1[i].length());
//str3.insert(index,str2[i]);
}
cout<<str3<<endl;
}
return 0;
}

POJ 1572 Automatic Editing 字符串替换,replace就够了的更多相关文章

  1. 字符串替换replace方法

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

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

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

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

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

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

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

  5. C# 字符串替换Replace

    C# 中的石strA.Replace(strB,strC)函数可以实现将strA中的strB替换为strC. 但是容易出错的地方是,这并不是就直接替换好了,此函数的返回值才是替换好的字符串,所以还要要 ...

  6. JQuery字符串替换replace方法

    在日常的js开发中,常常会用到JQuery, 当要把字符串中的内容替换时,如果使用类似C#的string.replace方法,如下 var str='aabbccaa'; str=str.replac ...

  7. C#自定义字符串替换Replace方法

    前一阵遇到一个如标题的算法题,是将原有字符串的某些片段替换成指定的新字符串片段,例如将源字符串:abcdeabcdfbcdefg中的cde替换成12345,得到结果字符串:ab12345abcdfb1 ...

  8. JavaScript字符串替换replace方法

    在日常的js开发中, 当要把字符串中的内容替换时,如果使用类似C#的string.replace方法,如下 var str='aabbccaa'; str=str.replace('aa','dd') ...

  9. Java之字符串替换replace()

    replace(char oldChar, char newChar)返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 而生成的 import java.uti ...

随机推荐

  1. CPU 使用率 100% 怎么办

    CPU 使用率 100% 怎么办 独家号 码上实战 作者 flyhero原文链接 工作中遇到CPU使用率100%,不要慌,一起来找出原因并fix掉它. 记住这里大致流程,当线上突然遇到时,也不必手足无 ...

  2. C++课程设计 通讯录管理系统 原码及解析

    设计题目:通信录管理系统 用C++设计出模拟手机通信录管理系统,实现对手机中的通信录进行管理. (一)功能要求 查看功能:选择此功能时,列出下列三类选择. A 办公类B 个人类C 商务类,当选中某类时 ...

  3. 优秀电路资料--- IOT方案

    完整的IOT方案 http://www.cirmall.com/circuit/4117/%E3%80%90%E5%BC%80%E6%BA%90%E3%80%91%E5%AE%8C%E6%95%B4% ...

  4. JS轮播图(网易云轮播图)

    JS 轮播图 写在前面 最聪明的人是最不愿浪费时间的人.--但丁 实现功能 图片自动切换 鼠标移入停止自动播放,显示按钮 点击按钮,实现前后翻 鼠标移入小圆圈,可以跳转到对应图片 点击左右两侧图片部分 ...

  5. 基于 element-plus 封装一个依赖 json 动态渲染的查询控件

    前情回顾 基于 el-form 封装一个依赖 json 动态渲染的表单控件 Vue3 封装第三方组件(一)做一个合格的传声筒 功能 使用 vue3 + element-plus 封装了一个查询控件,专 ...

  6. AtCoder Regular Contest 119 C - ARC Wrecker 2(同余定理+思维)

    Problem Statement There are NN buildings along the AtCoder Street, numbered 11 through NN from west ...

  7. 从C到C++过渡的3个原因

    从C到C++过渡的3个原因 3 reasons to transition from C to C++ 几十年来,嵌入式软件工程师们一直在争论他们是否应该使用C或C++.根据2019年嵌入式市场调查, ...

  8. 基于SSL(TLS)的HTTPS网页下载——如何编写健壮的可靠的网页下载

    源码下载地址案例开发环境:VS2010本案例未使用openssl库,内部提供了sslite.dll库进行TLS会话,该库提供了ISSLSession接口用于建立SSL会话. HTTP协议很简单,写个简 ...

  9. Jmeter-逻辑控制器If Controller的实例运用

    一.If Controller概述 Expression (must evaluate to true or false) :表达式(值必须是true或false),也就是说,在右边文本框中输入的条件 ...

  10. python 日期与字符串之间的转换

    1.str转换为datetime >>> from datetime import datetime >>> cday = datetime.strptime('2 ...