PAT (Advanced Level) 1092. To Buy or Not to Buy (20)
简单题。
#include<cstdio> #include<cstring> const int maxn=1e5+10; char s1[maxn],s2[maxn]; int cnt[300]; int tot[300]; int main() { scanf("%s",s1); scanf("%s",s2); memset(cnt,0,sizeof cnt); memset(tot,0,sizeof tot); for(int i=0;s1[i];i++) cnt[s1[i]]++; for(int i=0;s2[i];i++) tot[s2[i]]++; bool flag=1; int ans=0; for(int i=0;i<300;i++) { if(cnt[i]<tot[i]){ flag=0; ans=ans+tot[i]-cnt[i]; } } if(flag==0) printf("No %d\n",ans); else printf("Yes %d\n",strlen(s1)-strlen(s2)); return 0; }