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++]
  • 相关阅读:
    VBS处理AD帐号密码到期提醒的脚本[zt]
    简单几步手工扩容LVM、缩小LVM及移除磁盘(笔记)
    python加入进度条:tqdm 和 progressbar
    python的map和reduce函数
    python的lambda表达式
    python的推导式 —— 列表推导式、集合和字典推导式
    Pyspark中遇到的 java.io.IOException: Not a file 和 pyspark.sql.utils.AnalysisException: 'Table or view not found
    pyecharts绘制map地图
    pyecharts绘制geo地图
    sklearn.feature_extraction.text 的TfidfVectorizer函数
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3526467.html
Copyright © 2011-2022 走看看