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 ;
}
17-比赛1 B - 子串计算 Chef and his string challenge (string的运用)的更多相关文章
- 最长回文子串计算(fail)
题意: 给定一个字符串s,在s中找到最长的回文子字符串.您可以假设s的最大长度为1000. 例子: 输入: “babad” 输出: “bab” 注: “aba”也是一个有效的答案. 我的答案: 想法: ...
- 华为 oj 公共子串计算
水题,原来以为用dp数组 结果wrong了两次 我想还是自己小题大做了···呵呵·· 献给初学者作为参考 #include <stdio.h> #include <string.h ...
- 九度OJ 1149:子串计算 (计数、排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1026 解决:571 题目描述: 给出一个01字符串(长度不超过100),求其每一个子串出现的次数. 输入: 输入包含多行,每行一个字符串. ...
- C++ 基于STL的演讲比赛流程管理系统(sort算法+小型算法(accumulate)+内建函数对象+string字符串拼接+字符串截取+多个容器基础操作+与用户交互+文件的读写+保存+重建+整体文件数据的清空)
1 /* 2 比赛规则: 3 学校举行一演讲比赛,共12个人参加,比赛两轮,第一轮为淘汰赛 第二轮为决赛 4 每名选手都有对应的编号:如10001~10012 5 比赛方式:分组比赛 每组6人 6 第 ...
- 输入计算表达式,将他们存在string【】中
#include<stdio.h>#include<string>#include<string.h>#include<stdlib.h>#includ ...
- 【Java面试题】17 如何把一个逗号分隔的字符串转换为数组? 关于String类中split方法的使用,超级详细!!!
split 方法:将一个字符串分割为子字符串,然后将结果作为字符串数组返回. stringObj.split([separator],[limit])参数:stringObj 必选项.要被分解的 ...
- PHP实用小程序(四)
<HTML> <HEAD> <TITLE>访问文件时间属性</TITLE> </HEAD> <BODY> <? $Last ...
- wifi认证Portal开发系列(四):portal协议的java封装
一.报文封装类 AbstractPortalMsg.java Portal协议数据报文封装类 package org.yoki.edu.common.protocol.portal.msg; imp ...
- java springMVC 极致验证 非demo版
最近公司项目需要,做了个极致验证,自己在此做下记录. 先上效果图: 它的官网:http://www.geetest.com/ 里面有 身份验证.行为验证, 我这使用的为行为验证. 技术文档:ht ...
随机推荐
- java技术小白的入门
一.入门书籍 1,疯狂java讲义 2,java编程思想 3,Maven权威指南 4,Spring 3.0就是这么简单 5,Spring技术内幕 6,Spring实战 7,Maven实战 二.入门业务 ...
- Dynamics CRM用户创建后自动添加到团队报错
前两天在实现一项需求——用户创建后自动添加到一个叫做“全体员工”的团队的时候,遇到了一个奇怪的错误,CRM的错误日志只有一句简单的“Generic SQL error.”.一般遇到这个错误处理都非比较 ...
- 【起航计划 012】2015 起航计划 Android APIDemo的魔鬼步伐 11 App->Activity->Save & Restore State onSaveInstanceState onRestoreInstanceState
Save & Restore State与之前的例子Android ApiDemo示例解析(9):App->Activity->Persistent State 实现的UI类似,但 ...
- HCNA配置console线路密码password认证
1.华为设备配置主机名<Huawei>system <Huawei>system-view Enter system view, return user view wit ...
- 广搜最短路径变形,(POJ3414)
题目链接:http://poj.org/problem?id=3414 解题报告: 1.每个节点都是一个独立的状态 2.这里的状态转移就是有几种出路,4种:1.倒掉a中的水,2.把a中的水倒到b中去, ...
- 1.6 NBU Catalog备份还原
用户的数据保存到了磁盘或者磁带中,并且是安全的,NBU所在的机器还有可能发生故障,需要重新安装或者将NBU部署到其他的机器中继续使用. 在这种情况下,如何让NBU知道用户已经存在的备份策略和存储单元配 ...
- 2017.11.24 算法分析与设计------Gay格雷码
1. 格雷码问题: 对于给定的正整数n,格雷码为满足如下条件的一个编码序列: (1) 序列由2n个编码组成,每个编码都是长度为n的二进制位串. (2) 序列中无相同的编码. (3) 序列中位置相邻的两 ...
- 2017.11.14 C语言---指针的学习
第八章 善于利用指针 (1)指针是什么 1.内存区每一个字节都有一个编号,这就是"地址".地址形象化的被称为"指针".它能通过以它为地址的内存单元.地址指向(* ...
- CCF CSP 201712-2 游戏
题目链接:http://118.190.20.162/view.page?gpid=T67 问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐 ...
- 命令搜索命令whereis与which
whereis 命令名 #搜索命令所在路径及帮助文档所在位置,只能搜索系统命令. 选项: -b: 只查找可执行文件 -m: 只查找帮助文件 whoami whatis ls #ls 是什么命令 whi ...