码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 3973 AC's String (substr 强行匹配)

时间:2015-05-12 01:43:04      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:hdu   字符串匹配   


AC‘s String

Time Limit: 30000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1127    Accepted Submission(s): 316

Problem Description
You are given some words {Wi}. Then our stupid AC will give you a very long string S. AC is stupid and always wants to know whether one substring from S exists in the given words {Wi} .

For example, S = "abcd", and the given words {Wi} = {"bc", "ad", "dd"}. Then Only S[2..3] = "bc" exists in the given words. (In this problem, the first element of S has the index "0".)

However, this is toooooooooooo easy for acmers ! The stupid and evil AC will now change some letters in S. So could you solve this problem now?
 
Input
The first line is one integer T indicates the number of the test cases. (T <=20)

Then for every case, there is one integer n in the first line indicates the number of the given words(The size of the {Wi}) . Then n lines has one string which only has ‘a‘- ‘z‘. (1 <= n <= 10000, sigma|Wi| <= 2000000) .

Then one line has one string S, here |S| <= 100000.

Then one integer m, indicating the number of operations. (1 <= m <= 100000)

Then m lines , each line is the operation:

(1)Q L R , tell AC whether the S[L..R] exists in the given strings ;

(2)C X Y , chang S[X] to Y, here Y : ‘a‘-‘z‘ .
 
Output
First output “Case #idx:” in a single line, here idx is the case number count from 1.Then for each "Q" operation, output "Yes" if S[L..R] exists in the given strings, otherwise output "No".
 
Sample Input
1 2 ab ioc ipcad 6 Q 0 2 Q 3 4 C 1 o C 4 b Q 0 2 Q 3 4
 
Sample Output
Case #1: No No Yes Yes
 
Author
AekdyCoin
 
Source
2011 Multi-University Training Contest 14 - Host by FZU

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3973

题目大意:给一个字典,一个母串,Q查询母串的某个子串是否在字典中,C改变母串对应位置的字符

题目分析:强行substr模拟

#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
string s[10005], text;

int main()
{
    int T;
    scanf("%d", &T);
    for(int ca = 1; ca <= T; ca++)
    {
        printf("Case #%d:\n", ca);
        int n;
        scanf("%d", &n);
        char tmp[2000000];
        for(int i = 0; i < n; i++)
        {
            scanf("%s", tmp);
            s[i] = (string) tmp;
        }
        scanf("%s", tmp);
        text = (string) tmp;
        int q;
        scanf("%d", &q);
        char op[2];
        for(int i = 0; i < q; i++)
        {
            int l, r;
            char ch;
            scanf("%s", op);
            if(op[0] == 'Q')
            {
                bool flag = false;
                scanf("%d %d", &l, &r);
                string tmp;
                tmp = text.substr(l, r - l + 1);
                for(int i = 0; i < n; i++)
                {
                    if(tmp == s[i])
                    {
                        flag = true;
                        printf("Yes\n");
                        break;
                    }
                }
                if(!flag)
                    printf("No\n");
            }
            if(op[0] == 'C')
            {
                scanf("%d %c", &l, &ch);
                text[l] = ch;
            }
        }
    }   
}
 


HDU 3973 AC's String (substr 强行匹配)

标签:hdu   字符串匹配   

原文地址:http://blog.csdn.net/tc_to_top/article/details/45653667

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!