zoukankan      html  css  js  c++  java
  • 17-比赛1 B

    Chef's best friend Jerry gives Chef a string A and wants to know the number of string A that can be obtained from another string BA is made up of unique characters and every character in B can also be found in A. Chef is only allowed to remove string A from string B when it appears as a substring in string B. After one removal, the gap created will be closed and Chef can repeat the process.

    Chef wants you to help Jerry to find the answer.

    Input

    The first line of the input contains T, the number of test cases.

    The first line of each test case contains the string A.

    The second line of each test case contains the string B.

    Note: Please trim trailing whitespaces

    Output

    For each test case, output a single line consisting of the number of string A that can be obtained from string B as described.

    Constraints

    • 1 ≤ T ≤ 20
    • 1 ≤ |A| ≤ 26
    • A is made up of uppercase alphabet only
    • A does not have repeated characters
    • 1 ≤ |B| ≤ 3×105
    • B only contains characters present in A

    Example

    Input:
    2
    TIGER
    GTIGETIGERRERTIGTTIGERIGERER
    HELO
    HELHELLOO
    
    Output:
    5
    0
    

    Explanation

    Test case 1: 5 TIGERs can be obtained from code B as follows:
    GTIGETIGERRERTIGTTIGERIGERER
    GTIGETIGERRERTIGTIGERER
    GTIGERERTIGTIGERER
    GTIGERERTIGER
    GTIGERER
    GER



    主要是运用 string及其使用 的一道题

     1 # include <bits/stdc++.h>
     2 using namespace std;
     3 int main ()
     4 {
     5     int T; cin>>T;
     6     while(T--)
     7     {
     8         int sum = 0;
     9         string a; cin>>a;
    10         string b; cin>>b;
    11         int lena = a.length();
    12         size_t pos = b.find(a,0);
    13         cout<<pos<<endl;
    14         for(int i = 0;i < b.length();i++)
    15         {
    16             //substr()函数
    17             if(i+1>=lena&&b.substr(i+1-lena,lena)==a){
    18                 ++sum;
    19                 //erase()函数
    20                 b.erase(i+1-lena,lena);
    21                 i-=lena;
    22             }
    23         }
    24         cout<<sum<<endl;
    25     }
    26 
    27     return 0;
    28 }
  • 相关阅读:
    编程是点滴的积累
    Tech.ED 2005 北京 第二天印象
    Tech.ED 2005 北京 第三天印象
    别把事情弄的太复杂
    在看《青衣》
    可以用的开源包
    KVM虚拟机的性能问题
    [zz]kvmlibvirt的使用:创建虚拟机与快照
    KVM快照snapshot
    [zz]kvm环境快照(snapshot)的使用方法
  • 原文地址:https://www.cnblogs.com/darkboy/p/9379409.html
Copyright © 2011-2022 走看看