zoukankan      html  css  js  c++  java
  • Spoj-NPC2015A Eefun Guessing Words

    Eefun Guessing Words

    Eefun is currently learning to read. His way of learning  is unique, by trying to make every possible substring from a given string. However, when the string becomes longer, he can no longer remember all the substring. His friends want to test Eefun's skill by asking questions, given a string S, is there any substring that begins with letter X and ends with letter Y? According to Eefun, each substring contains at least 2 letters. As the given string S is pretty big, Eefun need your help to answer his friend's questions

    Input

    First line of input contain a single string S which was given by his friends.
    Second line contain a number N, the number of questions that Eefun's friends ask.
    Next N lines each consists of 2 characters, X and Y

    Output

    For each questions, output a single string "YA" if the substring exists, or "TIDAK" otherwise
    (YA means yes and TIDAK means no in Indonesian) 

    Example

    Input:
    HALO
    4
    H O
    L O
    A O
    O L 
    Output:
    YA
    YA
    YA
    TIDAK 

    Constraints:

    • 'A' ≤ X,Y ≤ 'Z'
    • 1 ≤ |S| ≤ 1.000.000
    • 1 ≤ N ≤ 1.000.000

    记一下每个字母第一次和最后一次出现的位置就好了

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<queue>
     8 #include<deque>
     9 #include<set>
    10 #include<map>
    11 #include<ctime>
    12 #define LL long long
    13 #define inf 0x7ffffff
    14 #define pa pair<int,int>
    15 #define mkp(a,b) make_pair(a,b)
    16 #define pi 3.1415926535897932384626433832795028841971
    17 #define mod 100007
    18 using namespace std;
    19 inline LL read()
    20 {
    21     LL x=0,f=1;char ch=getchar();
    22     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    23     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    24     return x*f;
    25 }
    26 int fst[210],lst[210];
    27 char s[1000010],x,y;
    28 int n,q;
    29 int main()
    30 {
    31     while (~scanf("%s",s+1))
    32     {
    33         memset(fst,0,sizeof(fst));
    34         memset(lst,0,sizeof(lst));
    35         n=strlen(s+1);
    36         for (int i=1;i<=n;i++)
    37         {
    38             if (!fst[s[i]])fst[s[i]]=i;
    39             lst[s[i]]=i;
    40         }
    41         q=read();
    42         for (int i=1;i<=q;i++)
    43         {
    44             scanf(" %c %c",&x,&y);
    45             if (fst[x]&&fst[y]&&fst[x]<lst[y])puts("YA");
    46             else puts("TIDAK");
    47         }
    48     }
    49 }
    Spoj NPC2015A
  • 相关阅读:
    Webpack中publicPath设置
    忘记Mysql的root密码怎么办?
    Visual Studio 2015上安装Entity Framework Power Tools
    Ubuntu下安装中文输入法
    Ubuntu如何选择更新源
    Orchard中如何配置远端发布
    .Net缓存管理框架CacheManager
    全新的membership框架Asp.net Identity(2)——绕不过的Claims
    全新的membership框架Asp.net Identity(1)——.Net membership的历史
    泛型使用中,解决类型转换问题
  • 原文地址:https://www.cnblogs.com/zhber/p/7153140.html
Copyright © 2011-2022 走看看