zoukankan      html  css  js  c++  java
  • UVa-156 Ananagrams(map映射)

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cmath>
     4 #include <cstdio>
     5 #include<cstdlib>
     6 #include<cstring>
     7 #include <vector>
     8 #include <queue>
     9 #include <map>
    10 #include <sstream>
    11 
    12 using namespace std;
    13 #define maxn 100100
    14 map<string, int>ma;
    15 std::vector<string> words;
    16 string func(string str) {
    17     string ans = str;
    18     for (int i = 0; i < ans.length(); i++) {
    19         ans[i] = tolower(ans[i]);
    20     }
    21 
    22     sort(ans.begin(), ans.end());
    23     return ans;
    24 }
    25 int main() {
    26     std::ios::sync_with_stdio(false);
    27     string str;
    28     while (cin >> str) {
    29         if (str[0] == '#') {
    30             break;
    31         }
    32         words.push_back(str);
    33         string r = func(str);
    34         if (!ma.count(r)) {
    35             ma[r] = 0;
    36         }
    37         ma[r]++;
    38     }
    39     std::vector<string> ans;
    40     for (int i = 0; i < words.size(); i++) {
    41         if (ma[func(words[i])] == 1) {
    42             ans.push_back(words[i]);
    43         }
    44         sort(ans.begin(), ans.end());
    45 
    46     }
    47     for (int i = 0; i < ans.size(); i++) {
    48         cout << ans[i] << endl;
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    Linux之权限
    Linux基础和文件操作
    linux之用户、用户组、用户提权
    linux之Vim使用
    java面向对象
    eclipse首选项常用设置
    eclipse中添加项目运行程序
    eclipse的基本配置
    eclipse安装
    Jemter压力测试核心流程
  • 原文地址:https://www.cnblogs.com/lino/p/9953871.html
Copyright © 2011-2022 走看看