题目链接:http://poj.org/problem?id=1572

输入数据时要注意,这里是string型

用getline(cin,origin[i]);

#include <string>
#include <iostream>
#include <algorithm>
#include <stdio.h> using namespace std; const int maxn = ;
int n;
string origin[maxn],rep[maxn],sequence; void init()
{
for(int i=;i<n;i++)
{
getline(cin,origin[i]);
getline(cin,rep[i]);
}
getline(cin,sequence);
} void work()
{
int pos;
int len;
for(int i=;i<n;i++)
{
pos=sequence.find(origin[i]);
len=origin[i].length();
while(pos!=string::npos)
{
sequence.erase(pos,len);
sequence.insert(pos,rep[i]);
pos=sequence.find(origin[i]);
}
}
cout<<sequence<<endl;
} int main()
{
cin>>n;
getchar();
while(n!=)
{
init();
work();
cin>>n;
getchar();
}
return ;
}

找子串替换(kmp)poj1572的更多相关文章

  1. LeetCode 28 Implement strStr() (实现找子串函数)

    题目链接: https://leetcode.com/problems/implement-strstr/?tab=Description   Problem : 实现找子串的操作:如果没有找到则返回 ...

  2. hdu 1711 Number Sequence(kmp找子串第一次出现的位置)

    题意:裸kmp 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string.h> using nam ...

  3. fzu Problem 2128 最长子串(KMP + strstr 经典好题)

     Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长.  Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...

  4. codevs 1204 寻找子串位置 KMP

    1204:寻找子串位置 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 18K  Solved: 8K Description 给出字符串a和字符串b,保 ...

  5. 翻转子串(string+KMP+程序猿面试金典)

    翻转子串 參与人数:1197时间限制:3秒空间限制:32768K 通过比例:35.03% 最佳记录:0 ms|8552K(来自 ) 题目描写叙述 假定我们都知道很高效的算法来检查一个单词是否为其它字符 ...

  6. Uva 12012 Detection of Extraterrestrial 求循环节个数为1-n的最长子串长度 KMP

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=3163">点击打开链接 题意: ...

  7. POJ3450最长公共子串【kmp】

    题目链接:http://poj.org/problem?id=3450 题目大意:给定n个长度不超过200的字符串,n < 4000.求这些字符串的最长公共子串,若没有,则输出 “IDENTIT ...

  8. leetcode-查找和替换模式

    一.题目描述 你有一个单词列表 words 和一个模式  pattern,你想知道 words 中的哪些单词与模式匹配.如果存在字母的排列 p ,使得将模式中的每个字母 x 替换为 p(x) 之后,我 ...

  9. HUST 1328 String (字符串前缀子串个数 --- KMP)

    题意 给定一个字符串S,定义子串subS[i] = S[0..i],定义C[i]为S中subS[i]的数量,求sigma(C[i])(0<=i<N). 思路 我们以子串结尾的位置来划分阶段 ...

随机推荐

  1. 使用Spring和JQuery实现视频文件的上传和播放

    Spring MVC可以很方便用户进行WEB应用的开发,实现Model.View和Controller的分离,再结合Spring boot可以很方便.轻量级部署WEB应用,这里为大家介绍如何使用Spr ...

  2. JS图片加载失败用默认图片代替

    1.onerror 事件会在文档或图像加载过程中发生错误时被触发. 当图片不存在时,将触发onerror,onerror 中img为 指定的默认图片. 图片存在则显示正常图片,图片不存在将显示默认. ...

  3. 转 OGG-01224 TCP/IP error 111 (Connection refused); retries exceeded.

    https://blog.csdn.net/yabingshi_tech/article/details/40620351 在源端启动goldengate pump进程,状态起初是running,后来 ...

  4. 3DSMAX 安装失败

    AUTO Uninstaller 更新下载地址 1.选择3DSMAX 2.选择3DSMAX的版本 3.点击“开始卸载”,然后重新安装就可以了

  5. 虚拟机中Centos7搭建本地仓库

    iso放入光驱(虚拟机光驱)后,设备目录是/dev/sr0 表示光驱,被挂载道 /run/media/c4t/CentOS\ 7\ x86_64目录下 [c4t@localhost ~]$ df文件系 ...

  6. pat1040. Longest Symmetric String (25)

    1040. Longest Symmetric String (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, ...

  7. php错误等级

    E_ALL - 所有的错误和警告(不包括 E_STRICT)   E_ERROR - 致命性的运行时错误   E_WARNING - 运行时警告(非致命性错误)   E_PARSE - 编译时解析错误 ...

  8. cmd/bat 判断日期,并删除文件

    代码来自互联网. ---------------------------------------- @echo off set a=2018-07-9 set ndate=%date:~,10%set ...

  9. 【第一篇笔记】C# 全局容错,全局异常

    网上找到两个方式,一个简单的只是做个记录,另一个能像QQ一样提交到后台. 方法一: static class Program { /// <summary> /// 应用程序的主入口点. ...

  10. mybatis VS hibernate

    转自:http://blog.csdn.net/firejuly/article/details/81902 第一章     Hibernate与MyBatis Hibernate 是当前最流行的O/ ...