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

70 篇文章 0 订阅


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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值