HDU 3973 AC ' s String (substr forced match)

Source: Internet
Author: User


AC ' s String Time limit:30000/10000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 1127 Accepted Submission (s):
problem DescriptionYou are given some words {Wi}. Then our stupid AC would give you a very long string S. AC was 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 the S have the index "0".)

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

Then for every case, there was one integer n in the first line indicates the number of the given words (the size of the {Wi} ) . Then n lines have one string which only have ' a '-' Z '. (1 <= N <= 10000, sigma| wi| <= 2000000).

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

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

Then M lines, 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 '. OutputFirst output "case #idx: ' In a ', ' here idx ' is the case number count ' from 1.Then for each" Q "operation, OUTP UT "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
 AuthorAekdycoin Source2011 multi-university Training Contest 14-host by Fzu

Topic Links: http://acm.hdu.edu.cn /showproblem.php?pid=3973

Topic: Give a dictionary, a string, q query whether a substring of a string is in the dictionary, c change the character of the corresponding position of the parent string

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


HDU 3973 AC ' s String (substr forced match)

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.