题干:

A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy. For example, if s=«aba», then strings «baobab», «aabbaa», «helloabahello» make him very happy and strings «aab», «baaa» and «helloabhello» do not.

However rather than being happy once, he loves twice as much being happy twice! So, when he got string t as a present, he wanted to cut it in two parts (the left part and the right part) so that each part made him happy.

Help s determine the number of distinct ways to cut the given string t into two parts in the required manner.

Input

The first line contains string s, consisting of lowercase English letters. The length of string s is from 1 to 1000 letters.

The second line contains string t, that also consists of lowercase English letters. The length of string t is from 1 to 106 letters.

Output

Print the sought number of ways to cut string t in two so that each part made shappy.

Examples

Input

aba
baobababbah

Output

2

Input

mars
sunvenusearthmarsjupitersaturnuranusneptune

Output

0

题目大意:

给你一个字符串s1和s2,让你把s2分割成两部分,然后每部分都可以与s1匹配(匹配的定义是任意删掉这部分中某几个字符后,剩下的字符与s1相同(包括顺序)),问最多有多少种分割的方法?

解题报告:

这是一道比较简单的C题,,值得注意的是如果cin读入字符串是156ms,,,scanf读入就是31ms了、、字符串长度1e6,,说明就算是单读一个字符串也最好别用cin啊、、

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e6 + 5;
char s1[MAX],s2[MAX];
int main()
{ scanf("%s",s1+1);scanf("%s",s2+1);int len1 = strlen(s1+1);int len2 = strlen(s2+1);int i=1, j=1;for(; i<=len1 && j<=len2;) {if(s1[i] == s2[j]) i++,j++;else j++;}if(i!=len1+1) {puts("0");return 0 ;}int tmp1 = j-1;for(i=len1,j=len2; j>=1 && i>=1;) {if(s1[i] == s2[j]) i--,j--;else j--;}if(i!=0) {puts("0");return 0 ;}int tmp2 = j+1;if(tmp2-tmp1>=0) {printf("%d\n",tmp2-tmp1);}else printf("0");return 0 ;}

【CodeForces - 523C】Name Quest (模拟)相关推荐

  1. Codeforces 235C Cyclical Quest (后缀自动机)

    题目链接: https://codeforces.com/contest/235/problem/C 题解: 对大串建后缀自动机 对询问串复制拆环.这里一定要注意是复制一个循环节不是复制整个串!循环节 ...

  2. CodeForces - 1526D Kill Anton(模拟)

    题目链接:https://vjudge.net/problem/CodeForces-1526D 题目大意:给出一个只有四种字母组成的字符串 AAA,要求将其重排列 BBB,使得贡献最大.贡献指的是, ...

  3. Codeforces Gym 100286I iSharp 模拟

    原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...

  4. Pyramid of Glasses CodeForces - 676B (dp,模拟)

    题目:新冠病毒肆虐了好几个月,彻底打乱了大家的学习和生活,终于在阳光明媚的某月,全球迎来了新冠抗战的顺利.为了庆祝全球协力共同抗疫的顺利,同学们准备了一场庆祝晚会,一起幻想以后美好的生活,他们用香槟酒 ...

  5. Codeforces 770D Draw Brackets! 模拟+中缀表达式

    http://codeforces.com/problemset/problem/770/D 我先找出每个括号'+'的位置和每个s[i]的高度 括号一定会出现[],就是s[i]='[' s[i+1]= ...

  6. CodeForces - 1141ESuperhero Battle简单模拟

    Superhero Battle 这道题卡了我一个多小时,最后也没有做出来,成功称为吊车尾... 思路什么的都没有问题,主要是,爆long long了,这个太可怕了,就因为一个中间变量忘记开longl ...

  7. codeforces#239_div2_B Garland 简单模拟

    题目地址:戳这里 题目大意:剪成花环,可以cut 但是不能粘贴--那么最多的方案就是,对每一种具体的颜色,第一字符串中出现的次数和第二个字符串中出现的次数取较小值. 先以为not obliged to ...

  8. CodeForces 158 B. Taxi(模拟)

    [题目链接]click here~~ [题目大意]n组团体去包车,每组团体的人数<=4,一辆车最多容纳4人,求所求车的数目最小 [解题思路]:思路见代码~~ // C #ifndef _GLIB ...

  9. CodeForces 148C Terse princess(模拟)

    太坑了...这题 #include<iostream> #include<cstdio> #include<algorithm> #include<cstdl ...

最新文章

  1. 界面 高炉系统_浅议工业互联网与传统计算机系统的关系
  2. 饱和气压与温度的关系_不同温度下空气中饱和水分含量及饱和蒸汽压
  3. CentOS6.7安装elasticsearch5.4 以及kibana
  4. 网络编程(part11)--socket模块方法及socket套接字属性
  5. swing 选择对话框_Java Swing –日期选择器对话框
  6. 【matplotlib笔记】plt.subplot()绘制子图
  7. android qq robot,安卓qq授权登陆源代码
  8. 【Kettle】如何输出固定格式报表
  9. 什么电脑在线录音软件好用
  10. 普通计算机安装服务器系统安装教程,Windows Server操作系统详细安装教程
  11. DMTF Redfish 概念介绍
  12. Netflix混沌工程手册Part 1:混沌工程简介
  13. 下载代码去 pudn.com每个编程人员都需要的网站
  14. 开发商给埋的五类网线,家中想改为千兆网络怎么办好?
  15. 赛效:超级简历在线简历助手教您一键制作简历
  16. Kubernetes 忘记token解决方案
  17. Redis图形化管理工具(Redis Desktop Manager)
  18. 雷军 1994 年写的代码,像诗一样优雅,不服不行~
  19. Linux常用命令(一) —— 开关机命令shutdown、远程登录命令ssh、远程拷贝文件命令scp
  20. android Activity管理器

热门文章

  1. [Leetcode][第40题][JAVA][数组总和2][回溯][剪枝]
  2. Android studio实现底部导航,AndroidStudio制作底部导航栏以及用Fragment实现切换功能...
  3. python可以测试java的代码吗_使用python做你自己的自动化测试--对Java代码做单元测试 (2)-导入第三方jar包裹...
  4. 语言求圆周率近似值改错_新证明解决了如何求无理数的近似值
  5. Codeforces Global Round 15 (A-D)没有C
  6. php代码expl,php – 参数号无效:参数未定义Explination
  7. 查询成绩小于85且是计算机的一项应用,查询练习2
  8. php if require,关于php:required_if Laravel 5验证
  9. 用c语言编程减法计算,求用C编个大数加减法运算程序
  10. Linux Kbuild文档 1