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;
}
相关推荐
fqbqrr4 小时前
2601C++,cmake与导入
c++
fqbqrr5 小时前
2601C++,编写自己模块
c++
wearegogog1235 小时前
基于 MATLAB 的卡尔曼滤波器实现,用于消除噪声并估算信号
前端·算法·matlab
一只小小汤圆5 小时前
几何算法库
算法
Evand J5 小时前
【2026课题推荐】DOA定位——MUSIC算法进行多传感器协同目标定位。附MATLAB例程运行结果
开发语言·算法·matlab
leo__5206 小时前
基于MATLAB的交互式多模型跟踪算法(IMM)实现
人工智能·算法·matlab
忆锦紫6 小时前
图像增强算法:Gamma映射算法及MATLAB实现
开发语言·算法·matlab
t198751286 小时前
基于自适应Chirplet变换的雷达回波微多普勒特征提取
算法
guygg886 小时前
采用PSO算法优化PID参数,通过调用Simulink和PSO使得ITAE标准最小化
算法
老鼠只爱大米6 小时前
LeetCode算法题详解 239:滑动窗口最大值
算法·leetcode·双端队列·滑动窗口·滑动窗口最大值·单调队列