心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
把每个单词全部转化成小写字母,然后对每个单词的字母排序,同时原单词也需要存储,因为输出时要用到。如果排序之后的单词只出现了一次,那么将它对应的原单词输出。
STL会不会降低coder设计算法的能力啊?我都担心了~现在成了STL控,多简单的程序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!="#")
    {
        
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 阅读(1264) 评论(6)  编辑 收藏 引用 所属分类: 题目分类:排序

FeedBack:
# re: UVa 156 Ananagrams
2011-04-26 14:45 | sai
你的stl用的好熟练。。我得多学习  回复  更多评论
  
# re: UVa 156 Ananagrams
2011-04-29 10:23 | sai
大牛。。我用vc6.0编译你的代码。。35个错误。。汗  回复  更多评论
  
# re: UVa 156 Ananagrams
2011-04-29 10:37 | sai
哈。。谢谢你。。终于把multimap<>搞懂了。。。  回复  更多评论
  
# re: UVa 156 Ananagrams
2011-08-21 15:47 | wawa
@sai
水母哥DBL  回复  更多评论
  
# re: UVa 156 Ananagrams
2013-08-11 16:03 | mistkafka
你的STL用得很好.
我感觉用STL 不会降低编码能力吧.
如果STL 都不用, 那么c跟c++就没太多区别了.
能更快的把你的想法用编码表达出来 就是好语言.  回复  更多评论
  
# re: UVa 156 Ananagrams
2013-08-11 16:06 | mistkafka
不过你的编码风格, 真的是该喷喷.  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理