FZU 2122 又见LKity【字符串/正难则反/KMP/把一个字符串中某个部分替换为另一个部分】
嗨!大家好,在TempleRun中大家都认识我了吧。我是又笨又穷的猫猫LKity。很高兴这次又与各位FZU的ACMer见面了。最近见到FZU的各位ACMer都在刻苦地集训,整天在日光浴中闲得发慌的我压力山大呀!于是,我准备为诸位编写一款小工具——LKity牌文本替换(众怒,:敢不敢更土点!)。这个小工具可以帮助诸位替换代码中的变量等功能,真心是一款编程,刷题必备的神器。其功能如下:
将给定的字符序列中所有包含给定的子串替换成另外一个给定的字符串。为了让其功能更加强大,替换过程中,将忽略大小写。并且不进行递归替换操作。
不过,作为笨笨的猫猫,我是心有余而力不足呀!希望诸位ACMer能帮我实现哈。(众FZU的ACMer:”……”);
Input
Output
Sample Input
abc
bc ab
aaa aaabca 333Abcc##
Sample Output
aaa aabc aba 333bc abc## 【分析】:正难则反。判断是否为给定应该替换之处,是则输出原串字符,否则输出替换串字符。 【代码】:
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<streambuf> using namespace std;
#define oo 10000000
int n;
char s1[],s2[],s3[+];
int main()
{
while(~scanf("%s",s1))
{
getchar();
gets(s2);
gets(s3);
int n1=strlen(s1);
int n3=strlen(s3); for(int i=;i<n3;i++)
{
int k=i,flag=;
for(int j=;j<n1;j++,k++)
{
if(tolower(s3[k]) != tolower(s1[j]))
{
flag=;
break;
}
}
if(!flag) printf("%c",s3[i]);
else
{
i=k-;
printf("%s",s2);
}
}
printf("\n");
}
}
暴力匹配
FZU 2122 又见LKity【字符串/正难则反/KMP/把一个字符串中某个部分替换为另一个部分】的更多相关文章
- FZU 2122 ——又见LKity——————【KMP字符串匹配】
Problem 2122 又见LKity Accept: 413 Submit: 1425Time Limit: 1000 mSec Memory Limit : 32768 KB Pr ...
- FZU 2122——又见LKity——————【字符串匹配、暴力】
Problem 2122 又见LKity Accept: 407 Submit: 1413Time Limit: 1000 mSec Memory Limit : 32768 KB Pr ...
- FZU 2122 又见LKity
直接模拟或者KMP #include <iostream> #include <string.h> #include <stdio.h> #include < ...
- FZU 2122 又见LKity(KMP+返回所有匹配位置)
基础kmp应用,找到所有匹配位置即可 #include<stdio.h> #include<string.h> #include<algorithm> #inclu ...
- P1197 [JSOI2008]星球大战(并查集判断连通块+正难则反)
P1197 [JSOI2008]星球大战(并查集判断连通块+正难则反) 并查集本来就是连一对不同父亲的节点就的话连通块就少一个. 题目描述 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统 ...
- Codeforces 870F - Path(数论+分类讨论+正难则反)
Codeforces 题目传送门 & 洛谷题目传送门 首先考虑 \(d(u,v)\) 是个什么东西,分情况讨论: \(u\not\perp v\),\(d(u,v)=1\) \(u\perp ...
- Educational Codeforces Round 74 (Rated for Div. 2)【A,B,C【贪心】,D【正难则反的思想】】
A. Prime Subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inpu ...
- 树上统计treecnt(dsu on tree 并查集 正难则反)
题目链接 dalao们怎么都写的线段树合并啊.. dsu跑的好慢. \(Description\) 给定一棵\(n(n\leq 10^5)\)个点的树. 定义\(Tree[L,R]\)表示为了使得\( ...
- CF 1005B Delete from the Left 【模拟数组操作/正难则反】
You are given two strings s and t. In a single move, you can choose any of two strings and delete th ...
随机推荐
- 【php】【特殊案例】数组调用方法
As of PHP 5.4.0, you can call any callable stored in a variable. <?php class Foo { static functio ...
- Java-basic-1
1. Java Standard Edition (Java SE) Java Enterprise Edition (Java EE): geared toward developing large ...
- usb hub 设备流程图
在此处负责而来:http://blog.csdn.net/xuelin273/article/details/38646851 下面的转载于:http://blog.csdn.net/qianguo ...
- $(MAKE) , make命令
make 定义了很多默认变量,像常用的命令或者是命令选项之类的,什么CC啊,CFLAGS啊之类.$(MAKE)就是预设的 make 这个命令的名称(或者路径).make -p 可以查看所有预定义的变量 ...
- 欧拉函数:HDU1787-GCD Again(欧拉函数的模板)
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HT1621控制的段式液晶驱动程序
MCU是STM8S207 /*LED 字模结构*/ typedef struct { char mChar; u8 mModal; }LED_MODAL_DEFINE; typedef struct ...
- UVa 11552 DP Fewest Flops
题解 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ...
- python - 自动化测试框架 - sendMail
# -*- coding:utf-8 -*- '''@project: Voctest@author: Jimmy@file: sendMail.py@ide: PyCharm Community E ...
- 常用软件URL
1.MSDN:https://msdn.itellyou.cn/ 2.软碟通(UltraISO)http://rj.baidu.com/soft/detail/11522.html?ald Ultra ...
- rails提供的validators
Instance Public methods attribute_method?(attribute)Link Returns true if attribute is an attribute m ...