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 提交 编辑 题目描述 家缠万贯来几时,我今停杯一问之 ...
随机推荐
- python操作oracle数据库
本文主要介绍python对oracle数据库的操作学习 包含:oracle数据库在Windows操作系统下的安装和配置.python需要安装的第三方拓展包以及基本操作的样例学习. 1 ...
- Autoware docker 环境安装
环境: ubuntu 16.04 GPU:GeForce 1070 nvidia 驱动型号:nvidia_driver_390.67 安装参考网址: https://github.com/C ...
- 如何用Adb连接Android手机 & unable to connect to 192.168.1.100:5555的原因和解决方法
利用adb来连接手机, 有两种方式: 1, wifi 2, usb. 1. 通过wifi, 利用adb来连接手机. 在pc的cmd中输入命令: adb connect 192.168.1.100 其中 ...
- pcieport 0000:00:1c.5: PCIe Bus Error
进入Linux系统 root身份 编辑/etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="quiet" 将quiet改为 pci=nomsi ...
- linux下监控用户的操作记录---录像播放性质
想知道用户登陆系统后都操作了什么,怎么办? 别急,linux下有一个script工具,专门记录终端会话中所有输入输出结果,并存放到指定文件中. 先看看怎么录制吧! 1.创建日志存放目录 # mkdir ...
- <正则吃饺子> :关于新项目的环境搭建(一)
来到新的公司,需要使用myeclipse.maven.svn.tomcat.mysql: 对于先前一直只用 netbeans 的我,在这里把环境搭建 的情况记录下来.来加深自己的学习和帮助后来者. 第 ...
- web面试常见问题
1事件继承 function ClassA(sColor) { this.color = sColor; this.sayColor = function () { al ...
- ASP.NET Core会议管理平台实战_汇总贴
ASP.NET Core会议管理平台实战 课程地址:https://ke.qq.com/course/389673?from=800004097#term_id=100464670 ASP.NET C ...
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before ...
- CodeForces 644B【模拟】
题意: 查询数 和 最大的队列容量+1: 按时间顺序 ti代表,第i个出线的时间: di代表,第i个需要处理的时间: 对于第i个输出他所需要的时间完成,或者拒绝进入输出-1: 思路: 真是MDZZ了, ...