CSP模拟45题解
已经快20场模拟赛没写题解了???
T1 难
下次我一定要先看 \(T1\) QAQ。
对于 \(a\) 串里第 \(i\) 位的字母,在 \(b\) 串里面会重复计算的是与 \(a\) 串里面 \(i\) 位字母相同的字母,所以将两个串中相同的字母的出现次数乘起来就行
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
typedef long long valueType;
const valueType inf = 1e18;
valueType len1, len2, ans;
char a[1100000], b[1100000];
// std::vector<std::pair<int, int>> prea[30], preb[30];
valueType suma[30], sumb[30];
int main() {
scanf("%s", a + 1);
scanf("%s", b + 1);
len1 = strlen(a + 1);
len2 = strlen(b + 1);
for (int i = 1; i <= len1; ++ i) {
int now = a[i] - 'a' + 1;
suma[now] ++;
}
for (int i = 1; i <= len2; ++ i) {
int now = b[i] - 'a' + 1;
sumb[now] ++;
}
for (int i = 1; i <= 26; ++ i) {
ans -= suma[i] * sumb[i];
}
ans += (len1 + 1) * (len2 + 1);
cout << ans << endl;
return 0;
}
/*
aa
aa
ac
aba
*/
标签:std,30,valueType,45,using,include,CSP,模拟
From: https://www.cnblogs.com/jueqingfeng/p/17729789.html