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;
}
相关推荐
君生我老19 分钟前
C++自写list类
c++
阿猿收手吧!33 分钟前
【C++】异步编程:std::async终极指南
开发语言·c++
REDcker37 分钟前
gRPC开发者快速入门
服务器·c++·后端·grpc
晚霞的不甘1 小时前
Flutter for OpenHarmony 可视化教学:A* 寻路算法的交互式演示
人工智能·算法·flutter·架构·开源·音视频
doupoa1 小时前
内存指针是什么?为什么指针还要有偏移量?
android·c++
望舒5131 小时前
代码随想录day25,回溯算法part4
java·数据结构·算法·leetcode
冉佳驹1 小时前
C++ ——— 异常处理的核心机制和智能指针管理
c++·异常捕获·异常继承体与多态·重载抛异常·raii思想·智能指针shared_ptr·weak_ptr指针
C++ 老炮儿的技术栈1 小时前
Qt 编写 TcpClient 程序 详细步骤
c语言·开发语言·数据库·c++·qt·算法
KYGALYX1 小时前
逻辑回归详解
算法·机器学习·逻辑回归
yuuki2332331 小时前
【C++】继承
开发语言·c++·windows