[ZPG TEST 114] Ali's English name "water problem"

Source: Internet
Author: User

    1. 1. Ali's English name

Ali recently remembered an English name, so he looked up a lot of names on the Internet. He found that some names could be partly derived from two different names, such as John's prefix "John" and Robinson's suffix "Son", which was Johnson.

Now he finds two favorite names (names can be treated as strings), with A and B, he wants to know a non-unprecedented prefix of a and a non-null suffix of B, and how many different strings can be formed by joining together.

Input format

Enter two lines, each representing the string A and B, and the string containing only lowercase English letters.

Output format

The output line, an integer, indicates how many different strings can be obtained.

Input sample

Output sample

Cat

Dog

9

Tree

Heap

14

Data scope and Constraints:

30% Data: String length not exceeding 2000

100% Data: string length not exceeding 100000

The problem is that this is a sign-in question ... I actually blew 0.

In fact, the water problem together, statistics a string in addition to the first letter of the number of other letters, statistics B string In addition to the number of other letters in the tail letter, and then the total number of programs minus those repeated.

#include <cstdio> #include <cstring>const int maxn = 100005;int N, m;char A[maxn], B[maxn];long long s[2][26], Ans;inline Long long getnum (int left, int. right, Char ch) {if (left <= 0) {left = 1;} Return s[right][ch-' a ']-s[left-1][ch-' a '];} /*interestingveryexciting*/int Main (void) {scanf ("%s%s", A + 1, B + 1), n = strlen (a + 1); m = strlen (b + 1); ans = (Long lon g) n * (Long Long) m;for (int i = 2; I <= n; ++i) {++s[0][a[i]-' a '];} for (int i = 1; i < m; ++i) {++s[1][b[i]-' a '];} for (int i = 0; i < ++i) {ans-= s[0][i] * s[1][i];} printf ("%lld\n", ans); return 0;}

  

[ZPG TEST 114] Ali's English name "water problem"

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.