zoukankan      html  css  js  c++  java
  • ACM题目————STL练习之Ananagrams

    Description

    Download as PDF

    Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot form another word. Such words are called ananagrams, an example is QUIZ.

    Obviously such definitions depend on the domain within which we are working; you might think that ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possible domain would be the entire English language, but this could lead to some problems. One could restrict the domain to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not in the same domain) but NOTE is not since it can produce TONE.

    Write a program that will read in the dictionary of a restricted domain and determine the relative ananagrams. Note that single letter words are, ipso facto, relative ananagrams since they cannot be ``rearranged'' at all. The dictionary will contain no more than 1000 words.

    Input

    Input will consist of a series of lines. No line will be more than 80 characters long, but may contain any number of words. Words consist of up to 20 upper and/or lower case letters, and will not be broken across lines. Spaces may appear freely around words, and at least one space separates multiple words on the same line. Note that words that contain the same letters but of differing case are considered to be anagrams of each other, thus tIeD and EdiT are anagrams. The file will be terminated by a line consisting of a single #.

    Output

    Output will consist of a series of lines. Each line will consist of a single word that is a relative ananagram in the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will always be at least one relative ananagram.

    Sample input

    ladder came tape soon leader acme RIDE lone Dreis peat
     ScAlE orb  eye  Rides dealer  NotE derail LaCeS  drIed
    noel dire Disk mace Rob dries
    #

    Sample output

    Disk
    NotE
    derail
    drIed
    eye
    ladder
    soon

    题目很简单,就是说给定一些字符串(以#结束),把这些字符串排序(不区分大小写),然后输出出现过两次以上的字符串(按字典顺序,也就是按ASII码表)。
    //Asimple
    #include <iostream>
    #include <vector>
    #include <string>
    #include <map>
    
    using namespace std;
    
    typedef multimap<string,string>::iterator mss_iter;
    multimap<string,string> m;
    string str;
    
    int main()
    {
        while ( cin >> str )
        {
            if( str == "#" ) break ;
            string str_copy(str);
            for(int i=0; i<str_copy.size(); i++)
                str_copy[i] = tolower(str_copy[i]);
            sort(str_copy.begin(),str_copy.end());//排序
            m.insert(make_pair(str_copy,str));//将排序后的字符串和原字符串放进一个容器
        }
        vector<string> S;
        for( mss_iter it=m.begin(); it!=m.end(); it++)
            if( m.count( it->first) == 1 )
                S.push_back( it->second) ;
        sort(S.begin(),S.end());
        for( int i=0; i<S.size(); i++)
            cout << S[i] << endl ;
    
        return 0;
    }
    


    低调做人,高调做事。
  • 相关阅读:
    对于捐赠承诺和劳务捐赠,不予以确认,但应在会计报表附注中披露
    R语言代写线性混合效应模型Linear Mixed-Effects Models的部分折叠Gibbs采样
    matlab代写MCMC贝叶斯方法用于加筋复合板的冲击载荷识别
    R语言代写dplyr-高效的数据变换与整理工具
    GIS代写遥感数据可视化评估:印度河流域上部的积雪面积变化
    R语言代写向量自回归模型(VAR)及其实现
    r语言代写实现似然的I(2)协整VAR模型弱外生性推理
    python代写缺失值处理案例分析:泰坦尼克数据
    Python代写高性能计算库——Numba
    matlab递归神经网络RNN实现:桨距控制控制风力发电机组研究
  • 原文地址:https://www.cnblogs.com/Asimple/p/5523507.html
Copyright © 2011-2022 走看看