• UVA 156 Ananagrams


    STL的应用

    #include<map>
    #include<cstdio>
    #include<string>
    #include<vector>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    string str, s;
    map<string, int>mp;
    vector<string>V, ans;
    void recordStr(string s){
        //cout << "here" << " " <<  s << endl;
        for(int i = 0;i < s.size();i ++)
            if(s[i] >= 'A' && s[i] <= 'Z') s[i] += 32;
        sort(s.begin(), s.end());
        map<string, int>::iterator it = mp.find(s);
        if(it == mp.end()) mp.insert(pair<string, int>(s, 1));
        else it->second ++;
    }
    bool isOnce(string s){
        for(int i = 0;i < s.size();i ++)
            if(s[i] >= 'A' && s[i] <= 'Z') s[i] += 32;
        sort(s.begin(), s.end());
        map<string, int>::iterator it = mp.find(s);
        return it->second == 1;
    }
    int main(){
        //freopen("in.cpp", "r", stdin);
        while(getline(cin, str, '
    ') && str != "#"){
            //cout << str << endl;
            str += " ";
            for(int i = 0;i < str.size();i ++){
                if(str[i] == ' '){
                    if(s.empty()) continue;
                    recordStr(s);
                    V.push_back(s);
                    s.clear();
                }else s.append(1, str[i]);
            }
            str.clear();
        }
        for(int i = 0;i < V.size();i ++) 
            if(isOnce(V[i])) ans.push_back(V[i]);
        sort(ans.begin(), ans.end());
        for(int i = 0;i < ans.size();i ++) cout << ans[i] << endl;
        return 0;
    }


  • 相关阅读:
    字符,字节和编码
    Linux网络参数和ifconfig
    默认网关 网关 子网掩码 广播地址
    S.M.A.R.T.记录几块ssd硬盘
    linux 别名
    echo 输出颜色
    Linux:echo命令详解
    centos下安装mongodb 通过shell脚本
    linux查看登录用户
    linux wget指定下载目录和重命名
  • 原文地址:https://www.cnblogs.com/anhuizhiye/p/3933179.html
Copyright © 2020-2023  润新知