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. codeforces 665B B. Shopping(水题)

    题目链接: B. Shopping time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. all.css

    @charset "utf-8"*{-webkit-tap-highlight-color:rgba(0,0,0,0); padding:0; margin:0;}body{ fo ...

  3. linux内存占用分析

    概述 想必在linux上写过程序的同学都有分析进程占用多少内存的经历,或者被问到这样的问题——你的程序在运行时占用了多少内存(物理内存)?通常我们可以通过top命令查看进程占用了多少内存.这里我们可以 ...

  4. python 简易音乐盒子

    #!/usr/bin/env python#-*- coding:utf-8 -*- from Tkinter import *import tkMessageBoximport urllib def ...

  5. AndroidStudio设置“自动导入包”

    setting –-> Editor –-> General –-> Auto Inport 勾选这两项 单击 Apply –-> ok

  6. 抓屏工具 faststone capture

    百度百科 http://baike.baidu.com/link?url=te51CfOKYIEmqT1jsyRwcB8Pnals5xQ8nUXk6trvBPGSJRBO5G7BEZL7cYQxmx8 ...

  7. Asset Catalog Help (七)---Customizing Image Sets for Size Classes

    Customizing Image Sets for Size Classes Add images to a set that are customized for display in diffe ...

  8. 1.13-1.14 Hive Action

    一.Hive Action 1.创建文件 [root@hadoop-senior oozie-apps]# pwd /opt/cdh-5.3.6/oozie-4.0.0-cdh5.3.6/oozie- ...

  9. 5-1条件运算符 & 5-2

    三目运算符 新建类: ConditionDemo 用三目运算符: package com.imooc.operator; public class ConditionDemo { public sta ...

  10. 内存、缓存、cpu之间的关系

    一.缓存和内存 许多人认为,“缓存”是内存的一部分 许多技术文章都是这样教授的 但是还是有很多人不知道缓存在什么地方,缓存是做什么用的 其实,缓存是CPU的一部分,它存在于CPU中 CPU存取数据的速 ...