UVA 10815-andy ' s first Dictionary

Source: Internet
Author: User
Andy, 8, has a dream-he wants to produce his very own dictionary. This is a easy task for him, as the number of words that he knows are, well, not quite enough. Instead of thinking up all the words himself, he had a briliant idea. From him bookshelf he would pick one of his favourite stories books, from which he would copy out all the distinct words. By arranging the words in alphabetical order, he is done! Of course, it is a really time-consuming job, and the is where a computer program is helpful.
You is asked to write a program this lists all the different words in the input text. In this problem, a word was defined as a consecutive sequence of alphabets, in upper and/or lower case. Words with is also to be considered. Furthermore, your program must is case insensitive. For example, words like "apple", "apple" or "apple" must is considered the same.
Input
The input file is a text with no more than lines. A input line have at most characters. Input is terminated by EOF.
Output
Your output should give a list of different words that appears in the input text, one in a line. The words should all is in lower case and sorted in alphabetical order. You can is sure that he number of distinct words in the text does not exceed 5000.
Sample Input
Adventures in Disneyland

Blondes were going to Disneyland, they came to a fork in the
Road. The sign read: "Disneyland left."

So they went home.
Sample Output
A
Adventures
Blondes
Came
Disneyland
Fork
Going
Home
Inch
Left
Read
Road
Sign
So
The
They
To
Both
Went
Were

When


Test instructions: Enter an English sentence, extract the words from the sentence, compare the size of the lowercase form of each word, go back to the weight, and then sort the dictionary order.

Ideas:

is mainly the string input this piece is troublesome, after entering, encounters the space or the other letter time, divides into a word, and when enters the time I remembers to convert the character to the lowercase letter, compares this word with the pre-ordered string comparison, if and previous heavy words, passes,

If it is not heavy, it is inserted in the correct position in the order of the dictionary sequence, and the last output string.


#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <
iomanip>//#include <ctype.h>//#include <cctype> using namespace std;
Char word[5000][200];
Char cur[200];
    int main (void) {//Freopen ("C.txt", "R", stdin);
    int flag=0;
    char c;
    int n=0;
    int l=0;
                while ((C=getchar ())!=eof) {if (Isalpha (c)) {Cur[n++]=tolower (c);
            flag=1;
                    } else {if (flag) {cur[n]= ');
                    n=0;
                    flag=0;
                    if (l==0) strcpy (word[l++],cur);

                        else {int j=0;
                            while (strcmp (Cur,word[j]) >0&&j<l) j + +; if (strcmp (word[j],cur) ==0) ContiNue
                                       if (j==l) {strcpy (word[l],cur);
                               l++; } else {for (int k=l;k&
                                      gt;j;k--) strcpy (word[k],word[k-1]);
                                           strcpy (word[j],cur);
                               l++;
            }}} else continue;


    }} for (int j=0;j<l;j++) printf ("%s\n", Word[j]);

return 0;
 }

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.