#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
char s1[1100],s2[1100];
int hash[128]={0};
cin>>s1;
cin>>s2;
for(int i=0;i<strlen(s2);i++)
{
hash[s2[i]]++;
}
for(int i=0;i<strlen(s1);i++)
{
hash[s1[i]]--;
}
int d=0,q=0;
bool t=false;
for(int i=0;i<128;i++)
{
if (hash[i]<0)
{
d=d-hash[i];
}
if (hash[i]>0)
{
t=true;
q=q+hash[i];
}
}
if (t) {cout<<"No"<<" "<<q;}
else {cout<<"Yes"<<" "<<d;}
system("pause");
return 0;
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
char s1[1100],s2[1100];
int hash[128]={0};
cin>>s1;
cin>>s2;
for(int i=0;i<strlen(s2);i++)
{
hash[s2[i]]++;
}
for(int i=0;i<strlen(s1);i++)
{
hash[s1[i]]--;
}
int d=0,q=0;
bool t=false;
for(int i=0;i<128;i++)
{
if (hash[i]<0)
{
d=d-hash[i];
}
if (hash[i]>0)
{
t=true;
q=q+hash[i];
}
}
if (t) {cout<<"No"<<" "<<q;}
else {cout<<"Yes"<<" "<<d;}
system("pause");
return 0;
}
简单hash的应用