把每個(gè)單詞全部轉(zhuǎn)化成小寫字母,然后對(duì)每個(gè)單詞的字母排序,同時(shí)原單詞也需要存儲(chǔ),因?yàn)檩敵鰰r(shí)要用到。如果排序之后的單詞只出現(xiàn)了一次,那么將它對(duì)應(yīng)的原單詞輸出。
STL會(huì)不會(huì)降低coder設(shè)計(jì)算法的能力???我都擔(dān)心了~現(xiàn)在成了STL控,多簡(jiǎn)單的程序map、set都用上了……
以下是我的代碼:
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cctype>
using namespace std;
int main()
{
/*
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
//*/
multimap<string,string> r;
string t;
while(cin>>t && t!="#")
{
string t_copy(t);
for(int i=0;i<t_copy.size();i++)
t_copy[i]=tolower(t_copy[i]);
sort(t_copy.begin(),t_copy.end());
r.insert(make_pair(t_copy,t));
}
vector<string> ans;
for(multimap<string,string>::iterator i=r.begin();i!=r.end();i++)
if(r.count(i->first)==1)
ans.push_back(i->second);
sort(ans.begin(),ans.end());
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<endl;
return 0;
}
posted on 2011-04-09 11:06
lee1r 閱讀(1302)
評(píng)論(6) 編輯 收藏 引用 所屬分類:
題目分類:排序