zoukankan      html  css  js  c++  java
  • 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;
    
    }
    


  • 相关阅读:
    Java vs Python
    Compiled Language vs Scripting Language
    445. Add Two Numbers II
    213. House Robber II
    198. House Robber
    276. Paint Fence
    77. Combinations
    54. Spiral Matrix
    82. Remove Duplicates from Sorted List II
    80. Remove Duplicates from Sorted Array II
  • 原文地址:https://www.cnblogs.com/zhangmingzhao/p/7256424.html
Copyright © 2011-2022 走看看