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 ...
随机推荐
- jsp内置对象及其方法
JSP中一共预先定义了9个这样的对象,分别为: request. response. session. application. out. pagecontext. con ...
- 树莓派开发板入门学习笔记1:[转]资料收集及树莓派系统在Ubuntu安装
参考教程(微雪课堂):http://www.waveshare.net/study/portal.php 树莓派实验室: http://shumeipai.nxez.com/2014/12/21/us ...
- JAVA基础篇—抽象类,抽象方法
class Shape package com.shape; public abstract class Shape { double area;// double per;// String col ...
- 线段树:CDOJ1597-An easy problem C(区间更新的线段树)
An easy problem C Time Limit: 4000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...
- day05 模块以及内置常用模块用法
内置常用模块详解: 1 time 2 datetime 3 random 4 os 5 sys 6 shutil 7 shelve 8 xml 9 configparser 10 hashlib ...
- SVM 与 LR的异同
LR & SVM 的区别 相同点 LR和SVM都是分类算法. 如果不考虑核函数,LR和SVM都是线性分类算法,也就是说他们的分类决策面都是线性的. LR和SVM都是监督学习算法. LR和SVM ...
- [adb 学习篇] adb pull
adb pull E:\uitest\testcase\CaseDemo\testcase\3dmark\3DMarkAndroid /sdcard/3DMarkAndroid 假设: E: ...
- Codeforces Round #412 Div. 2 第一场翻水水
大半夜呆在机房做题,我只感觉智商严重下降,今天我脑子可能不太正常 A. Is it rated? time limit per test 2 seconds memory limit per test ...
- PTA 11-散列4 Hard Version (30分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/680 5-18 Hashing - Hard Version (30分) Given ...
- xampp下bugfree部署
以Bugfree3.0.4为例,讲解如何搭建LAMP架构的Web服务器. Bugfree是一个XAMPP架构的网站,XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的搭建XAMP ...