HDU 3973 AC & #39; s String (forced match of substr ),

Source: Internet
Author: User

HDU 3973 AC's String (forced match of substr ),


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 edevil AC will now change some letters in S. So cocould 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
12ab 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:NoNo Yes Yes
Author AekdyCoin Source2011 Multi-University Training Contest 14-Host by FZU

Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 3973

Question: Give a dictionary, a parent string, and Q to query whether a substring of the parent string is in the dictionary. C changes the character at the corresponding position of the parent string.

Question Analysis: Forced substr Simulation

#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;            }        }    }   }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.