【CodeForces - 523C】Name Quest (模拟)
題干:
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 baobababbahOutput
2Input
mars sunvenusearthmarsjupitersaturnuranusneptuneOutput
0題目大意:
給你一個(gè)字符串s1和s2,讓你把s2分割成兩部分,然后每部分都可以與s1匹配(匹配的定義是任意刪掉這部分中某幾個(gè)字符后,剩下的字符與s1相同(包括順序)),問(wèn)最多有多少種分割的方法?
解題報(bào)告:
? 這是一道比較簡(jiǎn)單的C題,,值得注意的是如果cin讀入字符串是156ms,,,scanf讀入就是31ms了、、字符串長(zhǎng)度1e6,,說(shuō)明就算是單讀一個(gè)字符串也最好別用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 ;}?
總結(jié)
以上是生活随笔為你收集整理的【CodeForces - 523C】Name Quest (模拟)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 懒羊羊23岁了 网友齐为羊村小可爱送祝福
- 下一篇: Winaw32.exe - Winaw3