Most crossword puzzle fans are used to anagrams — groups of words with the same letters in differentorders — for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have thisattribute, no matter how you rearrange their letters, you cannot
form another word. Such words arecalled ananagrams, an example is QUIZ.Obviously such definitions depend on the domain within which we are working; you might thinkthat ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possibledomain
would be the entire English language, but this could lead to some problems. One could restrictthe domain to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not in thesame 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 relativeananagrams. 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.InputInput
will consist of a series of lines. No line will be more than 80 characters long, but may contain anynumber of words. Words consist of up to 20 upper and/or lower case letters, and will not be brokenacross lines. Spaces may appear freely around words, and at
least one space separates multiple wordson the same line. Note that words that contain the same letters but of differing case are considered tobe anagrams of each other, thus ‘tIeD’ and ‘EdiT’ are anagrams. The file will be terminated by a lineconsisting of
a single ‘#’.OutputOutput will consist of a series of lines. Each line will consist of a single word that is a relative ananagramin the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will alwaysbe at least one relative
ananagram.Sample Inputladder came tape soon leader acme RIDE lone Dreis peatScAlE orb eye Rides dealer NotE derail LaCeS drIednoel dire Disk mace Rob dries#Sample OutputDiskNotEderaildrIedeyeladdersoon

题解:就是查找字母重组后出现一次的单词;先将单词变为小写并按字典序排列,用map容器存储单词,然后用其映射

表示出现其次数。最后将出现一次的单词保存到set中,将其输出。

AC代码为:

#include<iostream>

#include<string>

#include<sstream>

#include<vector>

#include<map>

#include<algorithm>

using namespace std;

map<string,int> s;

vector<string>words;

string tr(string &s)

{   string ss=s;

    for(int i=0;i<ss.length();i++)

    {

        ss[i]=tolower(ss[i]);

    }

    sort(ss.begin(),ss.end());

    return ss;

}

int main()

{

    string st;

    while(cin>>st)

    {

        if(st[0]=='#')break;

        string r=tr(st);

        words.push_back(st);

        if(s.count(r)==0)s[r]=1;

        else s[r]++;

    }

    vector<string>ans;

    for(int i=0;i<words.size();i++)

    {

        if(s[tr(words[i])]==1)ans.push_back(words[i]);

    }

    sort(ans.begin(),ans.end());

    for(int i=0;i<ans.size();i++)

    {

        cout<<ans[i]<<endl;

    }

    return 0;

}

最新文章

  1. KnockoutJS 3.X API 第七章 其他技术(5) 使用其他事件处理程序
  2. 记录下Sublime Text Mac版的快捷键【转】
  3. OAF_开发系列12_实现OAF开发中URL中的标记和加密参数传递(案例)
  4. C# 字符串转义和反转义
  5. iOS - UIColor
  6. core文件分析
  7. github上如何合并别人的pull request
  8. 《ruby编程语言》笔记 1
  9. bootstrap弹出框居中
  10. python设计模式之装饰器模式
  11. CharacterController 角色控制器实现移动和跳跃
  12. eclipse failed to create the java virtual machine 问题图文解析(转)
  13. [日常] NOIP前集训日记
  14. Linux 系统调用sysconf
  15. IO复用(较详细)
  16. For in + 定时器
  17. requests库入门01-环境安装
  18. service 设计问题
  19. Zabbix实战-简易教程--DB类--ClickHouse
  20. 团队NABCD

热门文章

  1. 005.Kubernetes二进制部署kubectl
  2. HTTP的请求方式
  3. Ubuntu字符界面与图形界面的切换
  4. suseoj The wheat of the prime minister
  5. hdu 1863 畅通工程 (prim)
  6. nyoj 86-找球号(一)二分法
  7. 从0开始学前端(笔记备份)----HTML部分 Day1 HTML标签
  8. [学习笔记] 在Eclipse中使用Hibernate,并创建第一个工程
  9. systemd概念和运行机制
  10. 关闭Eslint检查