码迷,mamicode.com
首页 > 其他好文 > 详细

Ananagrams (多种stl)

时间:2018-07-22 00:29:17      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:ros   style   pac   ret   algorithm   clu   nan   单词   ams   

题意  给你一篇文章  以"#"号结束   按字典序求输出这篇文章中真正只出现过一次的单词   就是不能通过字母重新排列得到文章中另一个单词的单词

把每个单词的字母全部化为小写  再把这个单词中的字母按字典序排列  得到一个字符串  用map记下出现次数就行   只出现过一次的就是要输出的

 

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <string>
#include <set>
#include <sstream>
#include <vector>


using namespace std;

string s,t;
set<string>st;
vector<string>ans;
map<string,string>ss;
map<string,int>cnt;

int main()
{
    while(cin>>s&&s!="#")
    {
        t=s;
        ans.push_back(s);
        for(int i=0;i<t.length();++i)
        {
            t[i]=tolower(t[i]);

        }
        sort(t.begin(),t.end());
            ss[s]=t;
            ++cnt[t];

    }
    sort(ans.begin(),ans.end());
    for(vector<string>::iterator it=ans.begin();it!=ans.end();++it)
    {
        if(cnt[ss[*it]]==1) cout<<*it<<endl;
    }
    return 0;
}

 

Ananagrams (多种stl)

标签:ros   style   pac   ret   algorithm   clu   nan   单词   ams   

原文地址:https://www.cnblogs.com/Fy1999/p/9348256.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!