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;
}
相关推荐
啃啃大瓜几秒前
python常量变量运算符
开发语言·python·算法
熊文豪8 分钟前
【华为OD】找出通过车辆最多颜色
算法·华为od
塔中妖13 分钟前
【华为OD】环中最长子串2
算法·华为od
JCBP_33 分钟前
QT(3)
开发语言·汇编·c++·qt·算法
研梦非凡43 分钟前
ICCV 2025|基于曲线感知高斯溅射的3D参数曲线重建
人工智能·算法·3d
XFF不秃头44 分钟前
力扣刷题笔记-三数之和
c++·笔记·算法·leetcode
Pafey1 小时前
VS2022 + Qt5.9 中文乱码/项目设置utf-8编码
c++·qt·中文乱码
minji...1 小时前
C++ STL之list的使用
开发语言·c++
青草地溪水旁1 小时前
23 种设计模式
开发语言·c++·设计模式
一碗白开水一1 小时前
【第19话:定位建图】SLAM点云配准之3D-3D ICP(Iterative Closest Point)方法详解
人工智能·算法