文章

112

粉丝

69

获赞

218

访问

69.3k

头像
变位词 (哈希表)题解:
P1032
发布于2025年1月25日 16:24
阅读数 99

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

int n; 
unordered_map<char, int> h;

bool check(string a, string b)
{
	for(int i = 0; i < a.size(); i ++) h[a[i]]	++;
	for(int i = 0; i < b.size(); i ++) h[b[i]] --;
	for(auto v : h)
		if(v.second < 0) return false;
	return true;
}
int main()
{
	cin >> n;
	while(n --)
	{
		string s1, s2;
		h.clear();
		cin >> s1 >> s2;
		if(s1 == s2 ||check(s1, s2)) cout << "Yes" << endl;
		else  cout << "No" << endl;
	}
	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发