【PAT 甲级 简单哈希】1092 To Buy or Not to Buy (20 分)

#include<bits/stdc++.h>
using namespace std;

map<char, int> Cnt;

int main() {
    
    
    string origin, target;
    cin >> origin >> target;
    for(char ch: origin)
        Cnt[ch]++;
    for(char ch: target)
        Cnt[ch]--;

    int need = 0;
    bool enough = true;
    for(auto p: Cnt) {
    
    
        if(p.second < 0) {
    
    
            enough = false;
            need += -p.second;
        }
    }

    if(enough)
        cout << "Yes " << origin.size() - target.size() << endl;
    else
        cout << "No " << need << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/MYMarcoreus/article/details/114415798
今日推荐