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 }
  • 相关阅读:
    保护你的网站数字证书私钥
    Web安全防御从WAF到应用网关
    微信公众号【网络安全生命周期】部分文章目录
    一个SQL Injection漏洞在SDL流程中的闯关历险记
    Web Vulnerability Scanner 破解
    Web安全实战演练1-4
    转:WebCruiser Web Vulnerability Scanner 3 测评
    WAVSEP在Linux系统中部署时常见错误
    css属性操作
    前端基础CSS规则
  • 原文地址:https://www.cnblogs.com/darkboy/p/9379409.html
Copyright © 2011-2022 走看看