"Problem description"
There is an unreasonable encryption method: randomly inserting characters anywhere in a string. corresponding to the
The unreasonable method of decryption is to delete exactly those characters that are randomly inserted from the string.
Given the original text? And the encrypted string?, how many substrings can be decrypted to get the original text?
"Input Format"
Input the first line contains a string?, the second line contains a string?.
"Output Format"
The output line contains an integer that represents the number of substrings that can be decrypted to get the original text.
"Sample Input"
Abcabcabc
Cba
"Sample Output"
9
"Sample Interpretation"
Use [l,r] to denote the subscript at the beginning of the substring (numbering starting at 0), and these 9 scenarios are:
[0,6],[0,7],[0,8],[1,6],[1,7],[1,8],[2,6],[2,7],[2,8]
"Data size and conventions"
30% of the data, |t|≤1000.
For 100% of data, 1≤|t| ≤300,000,1≤|s|≤200.
Code:
#include <cstdio>#include<cstring>#include<iostream>#ifdef UNIX#definell "%lld"#else#definell "%i64d"#endifusing namespacestd;Chars[201],t[300001];intL1,l2;Long Longans;intMain () {Freopen ("encrypt.in","R", stdin); Freopen ("Encrypt.out","W", stdout); inti,j; scanf ("%s%s", t,s); L1=strlen (t); L2=strlen (s); I=j=0; intbe=-1, ss=-1; while(i<L1) { if(t[i]==s[0]&&be==-1) be=i; if(t[i]==S[j]) J++; if(j==L2) {J=0; Ans=ans+ (Long Long) (BE-SS) * (l1-i);//number of statistical programmesI=Be ; SS=be;//Prevent repetitive calculationsbe=-1; } I++; } cout<<ans; Fclose (stdin); Fclose (stdout); return 0;}
11.12 Simulation T1 encryption