用hash表记录字母出现的次数。
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int hashtabledianzhang[63]={0};
int hashtablexiaohong[63]={0};
int strtoindex(char a){
if(a>='0' && a<='9') return a-'0';
else if(a>='a' && a<='z') return a-'a'+10;
else if(a>='A' && a<='Z') return a-'A'+36;
}
int main(){
string a;
int duoyu=0, index, mark=1, queshao=0, i;
cin >> a;
for(i=0;i<a.size();i++){
index=strtoindex(a[i]);
hashtabledianzhang[index]++;
}
cin >> a;
for(i=0;i<a.size();i++){
index=strtoindex(a[i]);
hashtablexiaohong[index]++;
}
for(i=0; i<63; i++){
if(hashtabledianzhang[i]<hashtablexiaohong[i]){
queshao=queshao+(-hashtabledianzhang[i]+hashtablexiaohong[i]);
mark=0;
}
if(mark && hashtabledianzhang[i]!=hashtablexiaohong[i]){
duoyu =duoyu+(hashtabledianzhang[i]-hashtablexiaohong[i]);
}
}
if(mark) printf("Yes %d", duoyu);
else printf("No %d", queshao);
return 0;
}
如需转载请私聊作者