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 }
  • 相关阅读:
    过滤xml文件内容
    python接口自动化之通过接口模拟一通电话的多段对话
    浅谈python性能与优化
    监控之Linux系统监控命令大全
    mysql windows 5.7 安装版下载地址
    liunx 安装jdk
    下载文件,后台执行没问题,没下载文件
    spring boot thymeleaf
    spring security文档地址
    redis 可视化工具下载地址
  • 原文地址:https://www.cnblogs.com/darkboy/p/9379409.html
Copyright © 2011-2022 走看看