例題5-4 UVa 156 Ananagrams(STL:map)


タイトル:
白書を読む
要点:
木型DP木の最大の独立集を求めてmapを使う必要があって、もともと夏休みにC++を学んで更にSTLを学ぶと思って、それからやはり先に少し学んで、简単に使うことができると思っています.この問題は本のとおりにたたくことだ.C++は本当にCより使いやすいと言わざるを得ません.
mapの使用参考:クリックしてリンクを開く
#include
#include
#include
#include
#include
#include
using namespace std;
map cnt;
vector words;

string repr(const string s)
{
	string ans = s;
	for (int i = 0; i < ans.length(); i++)
		ans[i] = tolower(ans[i]);
	sort(ans.begin(), ans.end());
	return ans;
}

int main()
{
	int n = 0;
	string s;
	while (cin >> s)
	{
		if (s[0] == '#')
			break;
		words.push_back(s);
		string r = repr(s);
		if (!cnt.count(r))
			cnt[r] = 0;
		cnt[r]++;
	}
	vector ans;
	for (int i = 0; i < words.size(); i++)
		if (cnt[repr(words[i])] == 1)
			ans.push_back(words[i]);
	sort(ans.begin(), ans.end());		//       ,sort    string
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << "
"; return 0; }