这个题参考的大神的代码。。
我的AC代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef long long LL;
const int int_max = 0x07777777;
const int int_min = 0x80000000;
int result,t,pos;
int main(int argc, const char * argv[])
{
scanf("%d",&t);
while(t--){
char s[21000];
scanf("%s", s+1);
int len = strlen(s+1);
int pos = 0;
for(int i = 1; i <= len; i++){
if (s[i]=='?') {
pos = i;
}
}
int g[21000];
g[0] = 0;
for(int i = 1; i <= len; i++){
if(i==pos) g[i] = g[i-1];
else g[i] = g[i-1]^(1<<(s[i]-'a'));
}
map<int,int> mp1,mp2,mp3;
for(int i = 0; i <= len; i++){
mp1[g[i]]++;
if(pos && i >= pos) mp2[g[i]]++;
if(pos && i < pos) mp3[g[i]]++;
}
int res = 0;
map<int, int>::iterator it;
if(pos){
for(it=mp2.begin(); it!=mp2.end(); it++){
int x = it->first;
for(int j = 0; j < 26; j++){
int y = x ^ (1<<j);
if(mp3.find(y)!=mp3.end()){
res += mp2[x]*mp3[y];
}
}
}
}
for(it = mp1.begin(); it!=mp1.end(); it++){
res += it->second * (it->second-1)/2;
}
printf("%d\n", res);
}
}