错因
1.超时
2.开int会爆掉 一点要看数据 开long long
https://ac.nowcoder.com/acm/contest/95480/E
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll aaa[26];
ll bbb[1000010][26];
int main() {
ll n ;
cin >> n;
for (ll i = 0 ; i < n ; i++) {
int cishu;
char zimu;
cin >> cishu >> zimu ;
bbb[i][zimu - 'a'] = cishu; //存入每一组的字母和次数
aaa[zimu - 'a'] += cishu; //存入单个字母出现的总次数
}
int m ;
cin >> m;
ll cnt = 0;
if (m == 1) {
char k1;
cin >> k1;
cnt = aaa[k1 - 'a'];
} else {
char k1, k2;
cin >> k1 >> k2;
if (k1 != k2) {
for (ll i = 0 ; i < n; i++) {
if (bbb[i][k1 - 'a'] != 0 && bbb[i + 1][k2 - 'a'] != 0) cnt++;
}
} else {
for (ll i = 0; i < n ; i++) {
if (bbb[i][k1 - 'a'] != 0)cnt += bbb[i][k1 - 'a'] - 1;
}
}
}
cout << cnt;
return 0;
}