直接建表查询
#include <iostream>
#include <cstdio>
#include <vector>
#include <unordered_map>
using namespace std;
int main(){
string owner, eva;
cin >> owner >> eva;
unordered_map<char, int> table;
for(auto& c : owner){
if(table.find(c) == table.end()) table.insert({c, 0});
table[c]++;
}
int miss = 0;
for(auto&c : eva){
if(table.find(c) == table.end()){
miss++;
}else{
if(table[c] == 0) miss++;
else table[c]--;
}
}
if(miss == 0){
printf("Yes %d", owner.size() - eva.size());
}else{
printf("No %d", miss);
}
return 0;
}
字符串匹配算法
本文介绍了一种使用哈希表实现的简单字符串匹配算法,该算法能够有效地判断一个字符串是否为另一个字符串的子集,并统计缺失字符的数量。
413

被折叠的 条评论
为什么被折叠?



