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;
}
相关推荐
大白话_NOI13 分钟前
【洛谷 P2249】查找(深基 13. 例 1)+ 详细分析
c++·算法
吠品13 分钟前
C++实现m行n列带边框的长方形输出
算法
智者知已应修善业21 分钟前
【51单片机2个外部中断显示中断历时,初始化8左移3位共阳数码管】2024-6-6
c++·经验分享·笔记·算法·51单片机
码之气三段.1 小时前
edu158-B
c++
西安邮电大学1 小时前
分治算法详细讲解
java·后端·其他·算法·面试
code bean1 小时前
平衡相关性与多样性:推荐系统中的永恒博弈与 MMR 算法详解
算法
青梅橘子皮1 小时前
Linux---进程控制(2)(进程程序替换)
linux·c++·算法
Shan12051 小时前
经典问题——验证栈序列
数据结构·算法
chase_my_dream1 小时前
A-LOAM中scanRegistration.cpp详细讲解
c++·人工智能·自动驾驶
2501_906565121 小时前
勾股定理证明
算法