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;
}
相关推荐
t***5446 小时前
Clang 编译器在 Orwell Dev-C++ 中的局限性
开发语言·c++
kobesdu7 小时前
人形机器人SLAM:技术挑战、算法综述与开源方案
算法·机器人·人形机器人
yolo_guo7 小时前
redis++使用: hmset 与 hmget
c++·redis
handler018 小时前
拒绝权限报错!三分钟掌握 Linux 权限管理
linux·c语言·c++·笔记·学习
椰羊~王小美8 小时前
随机数概念及算法
算法
阿Y加油吧9 小时前
算法实战笔记:LeetCode 169 多数元素 & 75 颜色分类
笔记·算法·leetcode
t***5449 小时前
如何在Dev-C++中选择Clang编译器
开发语言·c++
不要秃头的小孩9 小时前
力扣刷题——509. 斐波那契数
python·算法·leetcode·动态规划
汉克老师9 小时前
GESP2023年9月认证C++三级( 第一部分选择题(9-15))
c++·gesp三级·gesp3级