洛谷 P1808 單詞分類

題目傳送門:https://www.luogu.com.cn/problem/P1808

非常有技巧的一個題,先試用sort函數將輸入的字符串排序,然後把排序後的字符串放入set集合中(借用set集合的去重),最後set中元素的個數就是答案。

#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

set<string> words;

int main(){
	int t;
	string temp;
	cin>>t;
	while(t--){
		cin>>temp;
		sort(temp.begin(),temp.end());
		words.insert(temp);
	}
	cout<<words.size()<<endl;
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章