18000 Two String 暴力。——— 读题
http://acm.scau.edu.cn:8000/uoj/mainMenu.html
18000 Two String
时间限制:1000MS 内存限制:65535K
提交次数:0 通过次数:0
题型: 编程题 语言: 不限定
Description
Given two string A and B and three kinds of operations as following:
(1)Push_back c add a character c at the back of string B
(2)Push_front c add a character c in front of string B
(3)Query calculate and output how many times B appears in A
could you calculate and output the right answer for each query?
输入格式
The first line contains the string A ,the second line contains the string B ,the third line contains an integer M (1 <= M <= 2000),
expressing the number of operation, Each of the following M lines contains one of the above-mentioned three operations.
total length of the string does not exceed 5000,all character in the input are the lower case Latin alphabet
输出格式
For each query, output a line containing the answer.
输入样例
abcabc
a
5
Query
Push_back b
Query
Push_front a
Query
aaaaa
a
5
Query
Push_back a
Query
Push_front a
Query
输出样例
2
2
0
5
4
3
来源
星尘
作者
admin
一定要注意到的是,
total length of the string does not exceed 5000,
就是所有样例的字符全加起来不会超过5000,其实我觉得这样给数据范围很坑爹。不如一个样例一个样例给我。
一直不敢做,其实就是暴力。
对于每种push,暴力进行。
每种查询,kmp一次。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
char str[maxn];
char sub[][maxn];
int lensub;
int lenstr;
int now;
int tonext[maxn];
void get_next(int now) {
int i = , j = ;
tonext[] = ;
while (i <= lensub) {
if (j == || sub[now][i] == sub[now][j]) {
tonext[++i] = ++j;
} else j = tonext[j];
}
}
int kmp(int now) {
get_next(now);
int i = , j = ;
int ans = ;
while (i <= lenstr) {
if (j == || str[i] == sub[now][j]) {
++i;
++j;
} else j = tonext[j];
if (j == lensub + ) {
ans++;
j = tonext[j];
}
}
return ans;
}
void work() {
lenstr = strlen(str + );
lensub = strlen(sub[now] + );
int q;
scanf("%d", &q);
char t[];
for (int i = ; i <= q; ++i) {
scanf("%s", t + );
if (t[] == 'Q') {
printf("%d\n", kmp(now));
} else {
char tt[];
scanf("%s", tt);
if (strcmp("Push_back", t + ) == ) {
sub[now][++lensub] = tt[];
} else {
for (int i = ; i <= lensub; ++i) {
sub[!now][i + ] = sub[now][i];
}
sub[!now][] = tt[];
now = !now;
lensub += ;
}
}
}
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
while (scanf("%s%s", str + , sub[now] + ) != EOF) work();
return ;
}
18000 Two String 暴力。——— 读题的更多相关文章
- 杭电ACM2076--夹角有多大(题目已修改,注意读题)
杭电ACM2076--夹角有多大(题目已修改,注意读题) http://acm.hdu.edu.cn/showproblem.php?pid=2076 思路很简单.直接贴代码.过程分析有点耗时间. / ...
- Codeforces 61B【怪在读题】
搞不懂为什么DFS的写法崩了,然后乱暴力,因为题意不是很懂... 主要还是读题吧(很烦 #include <bits/stdc++.h> using namespace std; type ...
- Codeforces 659B Qualifying Contest【模拟,读题】
写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...
- 【托业】【全真题库】TEST01-03-阅读题
[托业][全真题库]TEST01-03-阅读题
- C++的std::string的“读时也拷贝”技术!
C++的std::string的读时也拷贝技术! 嘿嘿,你没有看错,我也没有写错,是读时也拷贝技术.什么?我的错,你之前听说写过时才拷贝,嗯,不错的确有这门技术,英文是Copy On Write,简写 ...
- HDUOJ--2079选课时间(题目已修改,注意读题)
选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3268 09 宁波 现场 I - Columbus’s bargain 读题 最短路 难度:1
Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera ...
- Day1 读题解题提升
The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 昨晚做了训练赛,然后读题又自闭了QAQ. Average Score ZOJ - 3819 题意: ...
- 【ZZNU-oj-2116:人间不值得】(1亿以内的货币拼音转数值求折扣价原价)--hash+String大法好+字符串处理+超大暴力模拟题
B : 人间不值得 概览问题列表状态排名编辑 Progress Bar 时间限制:1 Sec 内存限制:256 MiB提交:146 答案正确:12 提交 编辑 题目描述 家缠万贯来几时,我今停杯一问之 ...
随机推荐
- ES6 新特性之Symbol
Symbol let s1 = Symbol('foo'); let s2 = Symbol('bar'); s1 // Symbol(foo) s2 // Symbol(bar) s1.toStri ...
- Struts2 Action 匹配的几种方式
下面针对我所遇见的Action的配置方法进行一下总结: 1.基本的匹配方法
- 并不对劲的BJOI2019
一些感想 现实并非游戏,并不支持反复刷关 猎人和防御工事一起被老山龙摧毁了: 猎人惨死雨中,结云村永无放晴之日: 猎人被狂龙病毒侵蚀,天空山上黑蚀龙泛滥. 好像这才是怪物猎人系列的真实结局呢 day ...
- 「LuoguP4147」 玉蟾宫(并查集
题目背景 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. 题目描述 这片土地被分成N*M个格子,每个格子里写着'R'或者'F ...
- openstack封装镜像
1.准备工作:准备你想要封装的各种镜像的iso,完整版本最简单版本都ok,只要能出虚拟机就行,这个大家去官网下载自己要的iso就可以,我这里用centos6.4最简版本,因为分给我的活让做这个的... ...
- 深度学习之Batch归一化
前言 以下内容是个人学习之后的感悟,转载请注明出处~ Batch归一化 在神经网络中,我们常常会遇到梯度消失的情况,比如下图中的sigmod激活函数,当离零点很远时,梯度基本为0 ...
- 使用 SourceTree 管理ios项目
SourceTree 是一个非常优秀的版本控制软件,他是一个客户端,方便我们去接入 GitHub .BitBucke 上面托管的代码. 声明(1——4是来自简书的非个人作品,仅仅保存资料学习使用) 一 ...
- 各浏览器userAgent汇总
浏览器 navigator.userAgent 备注 IE6 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) IE7 Mo ...
- 使用Java进行udp-demo编程时碰到的consumer和producter无法连接并报出“java.net.SocketException: Can't assign requested address”问题
在用Java编写了一个udp生产者和消费者的demo时,在生产者启动的时候会抛出异常 java.net.SocketException: Can't assign requested address ...
- eclispe的使用
1.eclipse 有的时候,子类包都已经写了,这时候要添加一个父类包,如果在包结构下是添加不了的,这时候需要切换格式: