zoukankan      html  css  js  c++  java
  • UVa 10815 Andy's First Dictionary

    Problem B: Andy's First Dictionary

    Time limit: 3 seconds


    Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his bookshelf he would pick one of his favourite story 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 this is where a computer program is helpful.

    You are asked to write a program that lists all the different words in the input text. In this problem, a word is defined as a consecutive sequence of alphabets, in upper and/or lower case. Words with only one letter are also to be considered. Furthermore, your program must be CaSe InSeNsItIvE. For example, words like "Apple", "apple" or "APPLE" must be considered the same.

    Input

    The input file is a text with no more than 5000 lines. An input line has at most 200 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 be in lower case, sorted in alphabetical order. You can be sure that he number of distinct words in the text does not exceed 5000.

    Sample Input

    Adventures in Disneyland
    
    Two blondes were going to Disneyland when 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
    in
    left
    read
    road
    sign
    so
    the
    they
    to
    two
    went
    were
    when
    

    Joke and image taken from the Web

    题目的意思是,给一篇文章,找出里面所有的单词,按字典序排序后输出

    只要把所有的单词全都找出来,然后排序,排好之后在输出时去掉重复的即可

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 
     6 using namespace std;
     7 
     8 string s[1000000];
     9 
    10 int main()
    11 {
    12     char temp[1000];
    13     int t=-1;
    14 
    15     while(gets(temp))
    16     {
    17         bool flag=false;
    18         for(int i=0;temp[i]!='';i++)
    19         {
    20             if(temp[i]>='a'&&temp[i]<='z')
    21                 if(flag)
    22                     s[t]=s[t]+temp[i];
    23                 else
    24                 {
    25                     t++;
    26                     s[t]=temp[i];
    27                     flag=true;
    28                 }
    29             else if(temp[i]>='A'&&temp[i]<='Z')
    30                 if(flag)
    31                     s[t]=s[t]+(char)(temp[i]+32);
    32                 else
    33                 {
    34                     t++;
    35                     s[t]=(char)(temp[i]+32);
    36                     flag=true;
    37                 }
    38             else
    39                 flag=false;
    40         }
    41     }
    42 
    43     sort(s,s+t+1);
    44 
    45     cout<<s[0]<<endl;
    46     for(int i=1;i<=t;i++)
    47         if(s[i]!=s[i-1])
    48             cout<<s[i]<<endl;
    49 
    50     return 0;
    51 }
    [C++]
  • 相关阅读:
    开源中最好的Web开发的资源
    数据结构慕课PTA 05-树9 Huffman Codes
    【读书笔记】C++ primer 5th 从入门到自闭(一)
    【PTA】浙江大学数据结构慕课 课后编程作业 03-树1 树的同构
    nuvoton980 generate yaffs2 format rootfs (九)
    nuvoton980 burn firmware to spi-nand (八)
    nuvoton980 kernel support bridge and nat(七)
    nuvoton980 kernel support tf card(六)
    nuvoton980 kernel support leds-gpio (五)
    nuvoton980 kernel support spi nand boot and rtc (四)
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3526467.html
Copyright © 2011-2022 走看看