|hash 散列字符串 要|1092 To Buy or Not to Buy (20分)

link

#include <string>
#include <iostream>
using namespace std;
int const MAXN = 100010;

int hashTable[MAXN] = { 0 };
int miss = 0;

int main() {
	string s1, s2;
	getline(cin, s1);
	getline(cin, s2);

	for (int i = 0; i < s1.length(); i++) {
		hashTable[s1[i]]++;
	}
	for (int i = 0; i < s2.length(); i++) {
		//if (hashTable[s1[i]] != 0) {
		//	hashTable[s1[i]]--;
		//}
		hashTable[s2[i]]--;
		if (hashTable[s2[i]] < 0)
			miss++;
	}

	if (miss == 0)
		cout << "Yes " << s1.length() - s2.length();
	else
		cout << "No " << miss;

	return 0;
}
上一篇:[洛谷P2396]yyy loves Maths VII $\&$ [CF327E]Axis Walking


下一篇:1092 To Buy or Not to Buy (20 分)