POJ 1572 Automatic Editing 字符串替换,replace就够了
题意不难理解,但是一开始还是没有看清楚题目。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就够了的更多相关文章
- 字符串替换replace方法
字符串替换replace方法: http://www.w3school.com.cn/jsref/jsref_replace.asp http://www.cnblogs.com/skywang/ar ...
- Python3字符串替换replace(),translate(),re.sub()
Python3的字符串替换,这里总结了三个函数,replace()和translate()和re.sub() replace() replace() 方法把字符串中的 old(旧字符串) 替换成 ne ...
- C#不区分大小写的字符串替换(Replace)函数
在.NET中,不调用C++/CLI,进行字符串替换有好几种方法: 1.最常用的,就是String实例.Replace(),但这个不能忽略大小写. 2.System.Text.Regex(Regular ...
- oracle学习笔记:字符串替换 replace、regexp_replace、translate函数
1.replace 函数 语法:replace(char, search_string, replacement_string) --针对字符串替换 功能: 将char中的字符串替换. 当re ...
- C# 字符串替换Replace
C# 中的石strA.Replace(strB,strC)函数可以实现将strA中的strB替换为strC. 但是容易出错的地方是,这并不是就直接替换好了,此函数的返回值才是替换好的字符串,所以还要要 ...
- JQuery字符串替换replace方法
在日常的js开发中,常常会用到JQuery, 当要把字符串中的内容替换时,如果使用类似C#的string.replace方法,如下 var str='aabbccaa'; str=str.replac ...
- C#自定义字符串替换Replace方法
前一阵遇到一个如标题的算法题,是将原有字符串的某些片段替换成指定的新字符串片段,例如将源字符串:abcdeabcdfbcdefg中的cde替换成12345,得到结果字符串:ab12345abcdfb1 ...
- JavaScript字符串替换replace方法
在日常的js开发中, 当要把字符串中的内容替换时,如果使用类似C#的string.replace方法,如下 var str='aabbccaa'; str=str.replace('aa','dd') ...
- Java之字符串替换replace()
replace(char oldChar, char newChar)返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 而生成的 import java.uti ...
随机推荐
- 2.Python入门-计算机组成、指令和程序、标识符、变量、数据类型、对象和变量关系、运算符
一.计算机的组成 计算机由两部分组成:硬件 和 软件 硬件包含:键盘.鼠标.显示器.CPU.主板.内存.硬盘 ... -硬件是看的见摸得着的 软件包含:系统软件(windows.macOS.Linux ...
- Keil编译后的Code,RO,RW,ZI分别表示什么以及和芯片Flash、SRAM的对应关系
在使用keil开发STM32应用程序时,点击Build后在Build Output窗口中经常会有如下信息:<ignore_js_op> 以前一直好奇这几个参数和实际使用的STM32芯片中F ...
- Redis学习笔记八:集群模式
作者:Grey 原文地址:Redis学习笔记八:集群模式 前面提到的Redis学习笔记七:主从复制和哨兵只能解决Redis的单点压力大和单点故障问题,接下来要讲的Redis Cluster模式,主要是 ...
- 出现异常org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping
这是因为yaml的配置文件格式出错导致的异常 原代码,仔细看数据源的配置没有和type的路径一致,而是下一级的目录,所以导致出错 使用shift+tab快捷键向左移动改变下就好了 最后成功运行
- Python+Selenium学习笔记10 - send_keys上传文件
在火狐浏览器上传文件 上传前,同一个HTML文件在火狐和Edge浏览器显示有些不同 这是Firefox浏览器的显示 这是Edge浏览器 上传后 1 # coding = utf-8 2 3 from ...
- 语义分割:基于openCV和深度学习(二)
语义分割:基于openCV和深度学习(二) Semantic segmentation in images with OpenCV 开始吧-打开segment.py归档并插入以下代码: Semanti ...
- GPU编程和流式多处理器(四)
GPU编程和流式多处理器(四) 3.2. 单精度(32位) 单精度浮点支持是GPU计算的主力军.GPU已经过优化,可以在此数据类型上原生提供高性能,不仅适用于核心标准IEEE操作(例如加法和乘法),还 ...
- PyTorch神经网络集成技术
PyTorch神经网络集成技术 create_python_neuropod 将任意python代码打包为一个neurood包. create_python_neuropod( neuropod_pa ...
- 英特尔Intel® Arria® 10 FPGA加速器设计
英特尔Intel Arria 10 FPGA加速器设计 Introducing the Intel Vision Accelerator Design with Intel Arria 10 FPGA ...
- 前台JS遍历Table的所有单元格数据内容
在日常开发过程中为了减少与后台服务器的交互次数,大部分的功能都会放到前台使用JS来完成. 例如:一个表中有ID(FOCUS_SEQ)和Name(COLUMNCTRL)两个字段,其中ID是自定义连续增长 ...