方法1:map容器代替hash散列
代码
#include <iostream>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 100000 + 5;
map<char, int> AppearCount;
vector<char> values;
int main(){
string ori, test;
cin>>ori>>test;
int LessCount = 0;
for(int i = 0; i < ori.size(); i++){
char c = ori[i];
AppearCount[c]++;
}
for(int i = 0; i < test.size(); i++){
char c = test[i];
if(AppearCount[c]){
AppearCount[c]--;
}else{
LessCount++;
}
}
int MoreCount = ori.size() - test.size();
if(LessCount)
printf("No %d", LessCount);
else printf("Yes %d", MoreCount);
return 0;
}
方法2:09,az,A~Z都用hash散列化为一个数字
if(c >= ‘0’ && c <= ‘9’) return c - ‘0’;//若是0-9,字符用数字0-9表示
if(c >= ‘a’ && c <= ‘z’) return c - ‘a’ + 10;//a z的字符用1035表示
if(c >= ‘A’ && c <= ‘Z’) return c -‘A’ + 36;//AZ的字符用36…表示