美文网首页
Ananagrams UVA - 156

Ananagrams UVA - 156

作者: HeoLis | 来源:发表于2019-02-11 18:31 被阅读4次

https://vjudge.net/problem/UVA-156

本题思路:把每个单词“标准化”,即全部转化为小写字母后再进行排序,然后再放到map中进行统计。关键在于“标准化”这个步骤。

#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

map<string, int> cnt;
vector<string> words;

// 将单词s进行标准化
string repr(const string &s) {
    string ans = s;
    for (int i = 0; i < ans.length(); i++)
        ans[i] = tolower(ans[i]);
    sort(ans.begin(), ans.end());
    return ans;
}

int main() {
    string s;
    while (cin >> s) {
        if (s[0] == '#')
            break;
        words.push_back(s);
        string r = repr(s);
        if (!cnt.count(r))
            cnt[r] = 0;
        cnt[r]++;
    }
    vector<string> ans;
    for (int i = 0; i < words.size(); ++i)
        if (cnt[repr(words[i])] == 1)
            ans.push_back(words[i]);
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i] << "\n";

    return 0;
}

set和map均支持insert、find、count、和remove操作,并且可以按照 从小到大的顺序循环遍历其中的元素。

相关文章

  • Ananagrams UVA - 156

    https://vjudge.net/problem/UVA-156 本题思路:把每个单词“标准化”,即全部转化为...

  • 156 - Ananagrams

    输入一些单词,找出所有满足下列条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词。在判断是否满足条件...

  • 素数练习题

    UVA 10375 UVA 10791 UVA10375 Choose and divide 题解 先素数打表,然...

  • 有趣的数学题

    UVA12716 UVA11582 UVA12716 GCD XOR 题解 参考这题用到2个结论a ^ b = c...

  • 字典树

    UVA 11488题目链接https://uva.onlinejudge.org/index.php?option...

  • ACM 国内外几个网站 & 题目分类

    国外 西班牙Valladolid大学 Uva:https://uva.onlinejudge.org俄罗斯Ural...

  • 皮肤科学小知识:

    对皮肤造成损伤的紫外线主要是UVB和UVA。 UVA能穿透玻璃对皮肤的穿透能力也比较强,可以深达真皮,UVA的生物...

  • ACM刷题打卡-151215

    UVa 272 - TEX Quotes 水题。字符替换。 UVa 10082 - WERTYU 第一次提交WA,...

  • 美肤mini课堂之防晒的理论知识

    1、关于UVA和UVB UVB是波短的紫外线,威力次于UVA,只能晒到表皮层,能把皮肤晒红、晒伤;UVA是波长的紫...

  • 2020-08-22

    达到精准美白的目的,防UVA更重要,之前一直有说法,UVA与老化的关系更直接。毕竟UVA的辐射量是UVB的近50倍...

网友评论

      本文标题:Ananagrams UVA - 156

      本文链接:https://www.haomeiwen.com/subject/qjtceqtx.html