- 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"