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 暴力。——— 读题的更多相关文章

  1. 杭电ACM2076--夹角有多大(题目已修改,注意读题)

    杭电ACM2076--夹角有多大(题目已修改,注意读题) http://acm.hdu.edu.cn/showproblem.php?pid=2076 思路很简单.直接贴代码.过程分析有点耗时间. / ...

  2. Codeforces 61B【怪在读题】

    搞不懂为什么DFS的写法崩了,然后乱暴力,因为题意不是很懂... 主要还是读题吧(很烦 #include <bits/stdc++.h> using namespace std; type ...

  3. Codeforces 659B Qualifying Contest【模拟,读题】

    写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...

  4. 【托业】【全真题库】TEST01-03-阅读题

    [托业][全真题库]TEST01-03-阅读题

  5. C++的std::string的“读时也拷贝”技术!

    C++的std::string的读时也拷贝技术! 嘿嘿,你没有看错,我也没有写错,是读时也拷贝技术.什么?我的错,你之前听说写过时才拷贝,嗯,不错的确有这门技术,英文是Copy On Write,简写 ...

  6. HDUOJ--2079选课时间(题目已修改,注意读题)

    选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 3268 09 宁波 现场 I - Columbus’s bargain 读题 最短路 难度:1

    Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera ...

  8. Day1 读题解题提升

    The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 昨晚做了训练赛,然后读题又自闭了QAQ. Average Score ZOJ - 3819 题意: ...

  9. 【ZZNU-oj-2116:人间不值得】(1亿以内的货币拼音转数值求折扣价原价)--hash+String大法好+字符串处理+超大暴力模拟题

    B : 人间不值得 概览问题列表状态排名编辑 Progress Bar 时间限制:1 Sec 内存限制:256 MiB提交:146 答案正确:12 提交 编辑 题目描述 家缠万贯来几时,我今停杯一问之 ...

随机推荐

  1. Java Web 项目打包脚本

    可用于 (但不限于) Eclipse 项目. 一次性生成:1. Java doc .zip 包:2. Java 源代码 .zip 包:3. Java 二进制文件 .jar 包:4. Java 源代码加 ...

  2. codeforces 702B B. Powers of Two(水题)

    题目链接: B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  3. Android Dalvik虚拟机

    虽然Android平台使用Java来开发应用程序,但Android程序却不是运行在标准Java虚拟机上的. 可能是出于效率和版权的考虑,Google为Android专门设计了一套虚拟机Dalvik V ...

  4. 《Linux内核修炼之道》精华分享与讨论(5)——Kernel地图:Kconfig与Makefile

    转自:http://blog.csdn.net/fudan_abc/article/details/5340408 Makefile不是Make Love 从前在学校,混了四年,没有学到任何东西,每天 ...

  5. sqlServer:convert()函数

    在oracle中对于时间格式的转换用到的比较多,相对也比较了解,现在换了新的项目组,使用sqlserver数据库,需要对这个数据库的一些常用函数进行重新学习和熟悉,现在根据w3c及网上博文对conve ...

  6. 性能测试之Jmeter学习(四)

    本节主要讲解:如何创建Web测试计划 如何创建一个简单的测试计划,用于测试web站点? 1.明确测试需求:我们会模拟5个并发用户,对Jakarta Web站点的网个页面进行访问,另外每个并发用户都会运 ...

  7. 纯java config配置Spring MVC实例

    1.首先创建一个Maven工程,项目结构如下: pom.xml添加Spring和servlet依赖,配置如下 <project xmlns="http://maven.apache.o ...

  8. 14.oauth2与open id connect 对比

    微博的授权机制 openIdConnect

  9. PYTHON实现DFS算法

    class Vertice: def __init__(self,index): self.no = index self.color = 0 # 0:white 1 gray 2 black sel ...

  10. HDU - 2612 Find a way 双起点bfs(路径可重叠:两个队列分别跑)

    Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...