1039 到底买不买

较水。

#include<iostream>
using namespace std;

int hashtable1[300] = {0},hashtable2[300]= {0};
int main() {
    string str1,str2;
    cin>>str1>>str2;
    for(int i = 0; i < str1.size(); ++i)
        hashtable1[str1[i]]++;
    for(int i = 0; i < str2.size(); ++i)
        hashtable2[str2[i]]++;
    int cnt1 = 0,cnt2 = 0;//分别表示多余的珠子和欠缺的珠子的总个数
    for(int i = 0; i < 300; ++i) { //遍历两个hashtable 
        if(hashtable1[i] >= hashtable2[i]) cnt1 += hashtable1[i] - hashtable2[i];
        else cnt2 += hashtable2[i] - hashtable1[i];
    }
    if(cnt2 != 0) printf("No %d",cnt2);
    else printf("Yes %d",cnt1);
    return 0;
}

 

posted @ 2020-02-19 12:13  tangq123  阅读(144)  评论(0编辑  收藏  举报