156 - Ananagrams
来源:互联网 发布:英语课文翻译软件 编辑:程序博客网 时间:2024/05/17 01:28
Uva
156 - Ananagrams
Ananagrams
Ananagrams
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 drIednoel dire Disk mace Rob dries#
Sample output
DiskNotEderaildrIedeyeladdersoon
题目大意:给出几行单词,以#结尾,按字典序(在乎大小写)输出words called ananagrams,ananagram的定义为:某个单词的字母的重新排列不能与其他单词相同(不在乎大小写)。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct node{ char s1[25],s2[25];//s1记录原单词,s2是s1全转化为小写,且字母按字典序排列好; bool f;//标记是否重复; bool operator<(const node& q)const{ return strcmp(s1,q.s1)<0; }}p[100];int main(){// freopen("a.txt","r",stdin); int c,i=0,j=0,f=0; while((c=getchar())!=EOF) { if(c==' '||c=='\n') { if(f) { p[i].f=1; p[i].s1[j]=p[i].s2[j]='\0'; sort(p[i].s2,p[i].s2+j); j=0; i++; } f=0; } else if(isalpha(c)) { f=1; p[i].s1[j]=c; p[i].s2[j]=tolower(c); j++; } else if(c=='#') break; } sort(p,p+i); for(j=0;j<i;j++) { for(int k=j+1;k<i;k++) if(strcmp(p[j].s2,p[k].s2)==0) p[j].f=p[k].f=0; if(p[j].f) cout<<p[j].s1<<endl; } return 0;}
- 156 - Ananagrams
- 156 - Ananagrams
- 156 - Ananagrams
- 156 - Ananagrams
- 156 - Ananagrams
- 156 - Ananagrams
- 156 - Ananagrams
- 156 - Ananagrams
- 156 - Ananagrams
- 156-Ananagrams
- UVa 156 - Ananagrams
- uva 156 Ananagrams
- UVA 156 - Ananagrams
- UVA 156 - Ananagrams
- UVa 156 - Ananagrams
- uva 156 - Ananagrams
- uva- 156-Ananagrams
- UVa 156 - Ananagrams
- spring入门
- CodeFluent Entities: How to add intellisense into Parts XML development in Visual Studio ?
- centos用户出现sudo无法使用,问题为:sudoers+文件中。此事将被报告
- 1111111
- Apache Struts2打开重定向/命令执行 CVE-2013-2251
- 156 - Ananagrams
- TQ210开发板NFS挂载android4.0.4的rootfs的方法
- android-goldfish-2.6.29升级到android-goldfish-3.4之后, 普通权限的apk读logs时只能读到自己的打印信息
- linux诡异的半连接(SYN_RECV)队列长度
- Eming
- Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedExcept
- nyoj-16-矩形嵌套
- spring mvc 框架搭建及详解
- 在全局页面缓存中显示登录信息