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;
}
相关推荐
武当豆豆3 小时前
C++编程学习阶段性总结
开发语言·c++
学不动CV了3 小时前
C语言32个关键字
c语言·开发语言·arm开发·单片机·算法
小屁孩大帅-杨一凡4 小时前
如何解决ThreadLocal内存泄漏问题?
java·开发语言·jvm·算法
A7bert7774 小时前
【YOLOv8-obb部署至RK3588】模型训练→转换RKNN→开发板部署
linux·c++·人工智能·python·yolo
Y1nhl5 小时前
力扣_二叉树的BFS_python版本
python·算法·leetcode·职场和发展·宽度优先
zyx没烦恼6 小时前
五种IO模型
开发语言·c++
EutoCool6 小时前
Qt窗口:菜单栏
开发语言·c++·嵌入式硬件·qt·前端框架
向阳逐梦7 小时前
PID控制算法理论学习基础——单级PID控制
人工智能·算法
2zcode7 小时前
基于Matlab多特征融合的可视化指纹识别系统
人工智能·算法·matlab
Owen_Q7 小时前
Leetcode百题斩-二分搜索
算法·leetcode·职场和发展