• UVA 10815 Andy's First Dictionary(字符处理)


    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
    
    构造一个不反复的字典。

    map一下就可以。

    (大写和小写)

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    typedef long long LL;
    using namespace std;
    #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
    #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
    #define CLEAR( a , x ) memset ( a , x , sizeof a )
    map<string,int>p;
    struct node{
        char s[1100];
    }e[5500*200];
    int cmp(node l1,node l2)
    {
        return strcmp(l1.s,l2.s)<0;
    }
    int main()
    {
         std::ios::sync_with_stdio(false);
         char str[100];
         int l=0;
         while(scanf("%s",str)!=EOF)
         {
             int len=strlen(str);
    //         cout<<"2333  "<<str<<endl;
             REP(i,len)
             {
                int j;
                if(isalpha(str[i]))
                {
                    char s1[1100];
                    int ll=0;
                    for(j=i;j<len;j++)
                    {
                        if(isalpha(str[j])) s1[ll++]=tolower(str[j]);
                        else  break;
                    }
                    s1[ll]='';
                    if(!p[s1]) { p[s1]=1;  strcpy(e[l++].s,s1);}
                    i=j-1;
                }
             }
         }
         sort(e,e+l,cmp);
         REP(i,l)  cout<<e[i].s<<endl;
         return 0;
    }
    


  • 相关阅读:
    Git 分支使用
    ansible 2.7 API
    zabbix api
    (四)ansible 通过堡垒机访问内网服务器
    C#实体对象出现中文处理乱码的问题
    mysql数据库数据(字段数过大)太多导入不了的解决方法
    MathWorks.MATLAB.NET.Arrays.MWArray”的类型初始值设定项引发异常 解决方法
    hibernate 主键生成方式
    HTN规划 jshop2
    自动驾驶
  • 原文地址:https://www.cnblogs.com/blfshiye/p/5097019.html
Copyright © 2020-2023  润新知