156 - Ananagrams (UVA)

题目链接如下:

Online Judge

我的代码如下:

cpp 复制代码
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
// #define debug

int main(){
    #ifdef debug
    freopen("0.txt", "r", stdin);
    freopen("1.txt", "w", stdout);
    #endif
    std::string str;
    std::vector<std::string> a, b, ans;
    std::map<std::string, int> mp;
    while(std::cin >> str && str != "#"){
        a.push_back(str);
        transform(str.begin(), str.end(), str.begin(), ::tolower);
        sort(str.begin(), str.end());
        b.push_back(str);
        mp[str]++;
    }
    for(int i = 0; i < b.size(); ++i){
        if(mp[b[i]] == 1){
            ans.push_back(a[i]);
        }
    }
    sort(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); ++i){
        printf("%s\n", ans[i].c_str());
    }
    #ifdef debug
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}
相关推荐
不会就选b1 小时前
算法日常・每日刷题--<贪心>14
算法
初願致夕霞2 小时前
C++11:类型推导与完美转发复盘笔记
c++
小猪写代码2 小时前
C++中什么是类,什么是对象
c++
mmmmath_34 小时前
LeetCode.541.反转字符串II
数据结构·算法·leetcode
Navigator_Z4 小时前
LeetCode //MySQL - 1251. Average Selling Price
c语言·算法·leetcode
醇氧5 小时前
MySQL 8.0 系统表损坏与引擎转换故障排查实战
数据结构·算法
大熊背6 小时前
《Color constancy by characterization of illumination chromaticity》之色度色域最大化算法(二)
算法·白平衡·色度·色温
钓鱼的肝6 小时前
梳理(1-5)
c++·经验分享·笔记·算法·青少年编程
HZZD_HZZD6 小时前
CSDN_批发市场水电漏损归因算法LAM的原理与落地
嵌入式硬件·物联网·算法