17-比赛1 B - 子串计算 Chef and his string challenge (string的运用)
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 B. A 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及其使用 的一道题
# include <bits/stdc++.h>
using namespace std;
int main ()
{
int T; cin>>T;
while(T--)
{
int sum = ;
string a; cin>>a;
string b; cin>>b;
int lena = a.length();
size_t pos = b.find(a,);
cout<<pos<<endl;
for(int i = ;i < b.length();i++)
{
//substr()函数
if(i+>=lena&&b.substr(i+-lena,lena)==a){
++sum;
//erase()函数
b.erase(i+-lena,lena);
i-=lena;
}
}
cout<<sum<<endl;
} return ;
}
最新文章
- 如何禁止内部viewPager滑动
- [No000081]SVN学习笔记1-服务端搭建
- in_array支持第三个参数,强制对数据类型检测
- 安卓开发笔记——关于图片的三级缓存策略(内存LruCache+磁盘DiskLruCache+网络Volley)
- Zabbix 监控 Nginx 状态
- 【leetcode】Subsets
- leetcode 146. LRU Cache ----- java
- 如何在协作开发安卓项目中打jar包给合作人
- 一.CSS工作原理
- 11.3 morning
- IOS中对于一些控件的抖动效果
- [Unity3D]Unity4全新的动画系统Mecanim
- push以及pop,shift,unshift
- 封装类(Merry May Day to all you who are burried in work ~)---2017-05-01
- 安装yum源和gcc编译器遇到的问题
- luogu P5320 [BJOI2019]勘破神机
- input[type=file]的美化
- C++11--时钟和计时器<;chrono>;
- Spring访问数据库(方式上跟HQL类似,每行记录映射一个实体类)
- 【SPL标准库专题(9)】 Datastructures:SplObjectStorage