UVa 156 map小用

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cctype> //olower 将大写字母转换为小写字母
#include <map>
using namespace std;

map<string,int> cnt;
vector<string> words;

string biaozhun(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()
{
//    freopen("in.txt","r",stdin);
    int n = 0;
    string s;
    while(cin>>s)
    {
        if(s[0]=='#')
            break;
        words.push_back(s);
        string r = biaozhun(s);
        if(!cnt.count(r))//查找r
            cnt[r] = 0;
        cnt[r]++; //只输出cnt[r]=1的 其他排除
//        cout<<cnt[r]<<endl;
    }
    vector<string> ans;
    for(int i = 0;i<words.size();i++)
    {
        if(cnt[biaozhun(words[i])]==1)  //联想上次的vector<int>pile[maxn]的声明,感觉string就等于一个数组
            ans.push_back(words[i]);
    }
        sort(ans.begin(),ans.end());
        for(int i = 0;i<ans.size();i++)
            cout<<ans[i]<<endl;
     return 0;

}


原文地址:https://www.cnblogs.com/mingrigongchang/p/6246273.html