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 }
  • 相关阅读:
    Redis(01)基础知识
    MySQL(05)触发器&事件&事务&锁
    MySQL(04)索引&存储过程
    MySQL(02)DDL&DML
    MySQL(03)表查询
    Go高级编程(01)
    兼容IE8灰色遮罩层处理方法
    AJAX请求跨域的问题
    Sql Server批量删除数据表
    [转]SQL操作日期
  • 原文地址:https://www.cnblogs.com/lino/p/9953871.html
Copyright © 2011-2022 走看看