UVa 156 - Ananagrams
来源:互联网 发布:json 能传两个对象吗 编辑:程序博客网 时间:2024/04/28 12:22
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 arelative 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
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>int cmp(const void *a,const void *b){ return strcmp((char*)a,(char *)b);}int main(){ int i=0,j=0; char c,word[1050][50],a[1050][30]; while((c=getchar())&&c!='#') { if(isalpha(c)) word[j][i++]=c; else if(i!=0) { word[j][i]='\0'; i=0; j++; } } for(i=0;i<j;i++) { memset(a[i],'0',sizeof(char)*26); a[i][26]='\0'; int len=strlen(word[i]); for(int k=0;k<len;k++) { c=tolower(word[i][k]); a[i][c-'a']++; } } for(i=0;i<j;i++) if(word[i]) for(int k=i+1;k<j;k++) if(word[k]&&strcmp(a[i],a[k])==0) { word[i][0]=0; word[k][0]=0; } qsort(word,j,sizeof(word[0]),cmp); for(i=0;i<j;i++) if(word[i][0])printf("%s\n",word[i]); return 0;}
- UVa 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
- UVa 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
- error C2143: syntax error : missing ';' before 'tag::id' 'BOOL' : redefinition; typedef cannot be ov
- JQuery操作iframe父页面与子页面的元素与方法
- OCJP(1Z0-851) 模拟题分析(五)
- 11款当前主流平板芯片横向对比评测
- iframe配合JQueryUI dialog实现登录对话框效果
- UVa 156 - Ananagrams
- 《毛泽东的军事艺术》读书笔记
- 【转】程序员技术练级攻略
- 大扬声器评测指标
- UML图(九种)
- 我的初梦《梦幻重游》开发记录二
- 网站提速的最佳实践-Best Practices for Speeding Up Your Web Site,来自雅虎开发者网络
- Android开发:一分钟学会使用Logcat调试程序
- SmartOS——与众不同的虚拟化技术