题目链接 https://www.acwing.com/problem/content/557/
c++ 可以哈希字符串,有内置函数,但是他不能哈希向量,即不能哈希数组,但是有一个接口,可以自己新定义一个哈希函数 https://www.acwing.com/blog/content/9/
unordered_set 就是哈希的类型
需要引入头文件#include<unordered_set>
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<unordered_set>
using namespace std;
typedef unsigned long long ull;
const int p = 131;
ull get_hash(int s[]){
ull res= 0;
for(int i =0;i<26;i++){
res = res*p+ s[i];
}
return res;
}
int main(){
int T;
cin >>T;
for (int cases = 1;cases<=T;cases ++){
int n;
string a,b;
cin>>n;
cin>>a>>b;
unordered_set<ull> S;
int s[26];
for(int i=0;i<n;i++){
for(int j = i;j<n;j++){
memset(s,0,sizeof s);
for(int k =i;k<=j;k++) s[b[k]- 'A']++; //这个B是什么鬼
S.insert(get_hash(s)); //直接哈希一个向量(哈希一个数组)
}
}
int res = 0;
for(int i =0;i<n;i++){
for(int j = i;j<n;j++){
memset(s,0,sizeof s);
for(int k = i;k<=j;k++) s[a[k]- 'A']++;
if(S.count(get_hash(s))) res++;
}
}
printf("Case #%d: %d\n",cases,res);
}
return 0;
}