• UVA156 Ananagrams


    问题链接UVA156 Ananagrams

    题意简述输入一个文本文件,从中提取出一些单词输出,输出的单词按照文本文件中的原来样子输出(字母大小写不变)。对于所有的单词,若字母不分大小写,单词经过重排顺序,与其他单词相同,这些单词则不在输出之列。

    问题分析用C++语言编写程序,可以练习使用STL的功能。。另外一点,C++编写程序效率会更高。

    程序说明:使用了容器类map和vector。其他都是套路。

    AC的C++语言程序如下:

    /* UVA156 Ananagrams */
    
    #include <iostream>
    #include <map>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    map<string, int> dict;
    vector<string> words;
    vector<string> ans;
    
    string getkey(const string& s)
    {
        string key = s;
    
        for(int i = 0; i < (int)key.length(); i++)
            key[i] = tolower(key[i]);
    
        sort(key.begin(), key.end());
    
        return key;
    }
    
    int main()
    {
        string s;
    
        while(cin >> s) {
            if(s[0] == '#')
                break;
    
            string key = getkey(s);
    
            if(dict.count(key) == 0)
                dict[key] = 0;
            dict[key]++;
    
            words.push_back(s);
        }
    
        for(int i=0; i<(int)words.size(); i++)
            if(dict[getkey(words[i])] == 1)
                ans.push_back(words[i]);
    
        sort(ans.begin(), ans.end());
    
        for(int i=0; i<(int)ans.size(); i++)
            cout << ans[i] << "
    ";
    
        return 0;
    }


  • 相关阅读:
    引擎优化笔记3
    IP/TCP/UDP checsum
    引擎优化笔记2
    Hive Map结构
    clickhouse概述
    Hive小文件合并
    hive计算引擎~Tez
    Hive优化~参数优化
    Hive分析窗口函数(三) CUME_DIST,PERCENT_RANK
    HIve实现数据抽样
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7564472.html
Copyright © 2020-2023  润新知