11.12 Simulation T1 Encryption

Source: Internet
Author: User

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.