UVA 156-ananagrams (string sort sequential output no repeating words)

Source: Internet
Author: User
Tags strcmp

AnanagramsTime limit:MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatus

Description


Ananagrams

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

Obviously such definitions depend on the domain within which we is working; You might think this athene is a ananagram, whereas any chemist would quickly produce ethane. One possible domain would be the entire 中文版 language, but this could leads to some problems. One could restrict the domain to, say, Music, in which case scale becomes a relative Ananagram (laces are not in t He same domain) but NOTE was not since it can produce TONE.

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

Input

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

Output

Output would consist of a series of lines. Each line would consist of a single word, a relative ananagram in the input dictionary. Words must is output in lexicographic (case-sensitive) order. There always is 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  Driedn Oel dire Disk Mace Rob dries#

Sample Output

Disknotederaildriedeyeladdersoon

Test instructions: Each word is converted to lowercase letters, for each word, see its letter reflow to get the words in all the input words appear, if not appear, output the original word. All words to be output are sorted in dictionary order.
Idea: Store and sort all the input words, convert all the letters to lowercase and store them, sort each word that is stored separately. Then to another store and sort the word search again, see if each word appears only once, appear once, will be corresponding to the original word output.

PS: Really can't stand, do not use sort to sort strings, and re-learn to use qsort to sort strings.


#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #include <    Iostream>using namespace Std;char Str[110][30];char rep[110][30];int cmp_char (const void *a,const void *b)//sorting letters { return * (char *) a-* (char *) b;} int cmp_string (const void *a,const void *b)//Sort the word {return strcmp (char *) A, (char *) b);}    int main () {int i,j;    int cnt=0;    int Len;    int sum;    Char a[30];        while (~SCANF ("%s", a)} {if (a[0]== ' # ') break;    strcpy (Str[cnt++],a);    } qsort (Str,cnt,sizeof (str[0]), cmp_string);    memset (rep,0,sizeof (rep));        for (i=0; i<cnt; i++) {Len=strlen (str[i]); for (j=0; j<len; J + +) {if (str[i][j]>= ' A ' &&str[i][j]<= ' Z ') rep[i][j]=str[            i][j]+32;        else Rep[i][j]=str[i][j];    } qsort (Rep[i],len,sizeof (char), Cmp_char);        } for (i=0;i<cnt;i++) {sum=0;  for (j=0;j<cnt;j++)          if (strcmp (Rep[i],rep[j]) ==0) sum++;    if (sum==1) printf ("%s\n", Str[i]); } return 0;}


UVA 156-ananagrams (string sort sequential output no repeating words)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.