uva 156 - Ananagrams
来源:互联网 发布:小米商城抢购软件 编辑:程序博客网 时间:2024/05/01 23:50
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 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
找出不重复的单词按字典序排序,排序区分大小写,重复是所有字母一样顺序不同无所谓不区分大小写。
很蛋疼我把标记数组定义在堆区就是主函数外面就对了,而定义在主函数内也就是栈区就runtime error了,数组大小都是一样的
奇怪╮(╯▽╰)╭求指教
#include <stdio.h>
#include <string.h>
#define max 1001
char word[max][100],key[max][100],s[100],s1[100];
int a[max];
void change()
{
int l=strlen(s),i,j;
for (i=0;i<l;i++)
if (s[i]<='Z') s1[i]=s[i]+32;
else s1[i]=s[i];
for (i=0;i<l-1;i++)
for (j=i+1;j<l;j++)
if (s1[i]>s1[j]) {s1[l]=s1[i];s1[i]=s1[j];s1[j]=s1[l];}
s1[l]='\0';
};
int pk(char s1[],char s2[])
{int l1=strlen(s1),l2=strlen(s2),i;
l1=l1<l2 ? l1:l2;
for (i=0;i<l1;i++)
{if (s1[i]>s2[i]) return 1;
if (s1[i]<s2[i]) return 0;
}
};
void main ()
{int sum=0,i,j,f;
while (scanf("%s",&s))
{if (s[0]=='#') break;
change();
f=1;
for (i=1;i<=sum;i++)
if (strcmp(key[i],s1)==0) {f=0;a[i]=0;break;}
if (f) {++sum;a[sum]=1;strcpy(word[i],s);strcpy(key[i],s1);}
}
for (i=1;i<sum;i++)
for (j=i+1;j<=sum;j++)
if (pk(word[i],word[j]))
{strcpy(s,word[i]);strcpy(word[i],word[j]);strcpy(word[j],s);
a[0]=a[i];a[i]=a[j];a[j]=a[0];
}
for (i=1;i<=sum;i++)
if (a[i]) puts(word[i]);
}
- 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
- C3p0使用时出现的异常及解决方案
- iOS NSUserDefaults使用方法
- RTFSC (Read the fucking source code )
- 采用cocos2d 1.1版本若是要实现屏幕为竖屏显示怎样修改
- 移动网络名词理解(5)---APN、wap、net
- uva 156 - Ananagrams
- 浅谈数据库连接
- 简单教你配置高性能的vi编辑器(ctags+vim+cscope)
- 笔试中遇到的问题总结(一)
- 笔试中遇到的问题总结(一)
- 黑马程序员学习笔记六——java.IO小细节或许影响全局。
- 动画学习1 Animating Views with Blocks
- Spring技术内幕3Spring AOP的实现
- 1.2.9 数组中大小最接近的两个元素差