zoukankan      html  css  js  c++  java
  • 杭电2027--单词数

    单词数

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 35863    Accepted Submission(s): 8662


    Problem Description
    lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
     

     

    Input
    有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
     

     

    Output
    每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
     

     

    Sample Input
    you are my friend
    #
     

     

    Sample Output
    4
     

     

    Author
    Lily
     

     

    Source
     

     

    Recommend
    linle   |   We have carefully selected several similar problems for you:  2074 2054 1251 2058 2073 
    //做到差点心碎 ; AC代码:
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm> 
     4 char str[1010], ch[110][110] , cmp[1010];
     5 using namespace std ;
     6 
     7 void sweep(char a[], char b[])
     8 {
     9     char c[1010] ;
    10     strcpy(c, a); strcpy(a, b); strcpy(b, c) ;
    11 }
    12 int main()
    13 {
    14     
    15     while(gets(str), str[0] != '#')
    16     {
    17         memset(ch, '', sizeof(ch)) ;
    18         int i, j, front=-1, rear=-1, time = 0 ; //标记 ; 
    19         int len = strlen (str) ; 
    20     //    printf("%d
    ", len) ;
    21         int t = 0 ;
    22         for(i=0; i<len; i++)
    23         {
    24             if(str[i] == ' ')
    25             t++ ;
    26         }
    27         if(t == len || len == 0)     //没有输入 || 输入全是空格  → 结果为 0 ; 
    28         {
    29             printf("0
    ") ;
    30             continue ;
    31          }
    32          else
    33          {
    34          
    35             for(i=0; i<len; i++)
    36             {
    37                 if(str[i] !=' ' && (str[i-1] == ' ' || i == 0))
    38                 front = i ; 
    39                 if(str[i] != ' '&& (str[i+1]==' ' || str[i+1] == ''))
    40                 rear = i ;
    41                 int ti = 0 ;
    42             //    printf("%d %d
    ",front, rear) ;
    43                 if(rear != -1 && front != -1)   //单词分离出来 ; 
    44                 {
    45                 //printf("%d %d
    ", front, rear) ;
    46                     for(i=front; i<=rear; i++ )
    47                     {
    48                         ch[time][ti++] = str[i] ;
    49                     }        
    50                     time++ ; rear = -1 ; front = -1 ;
    51                 }
    52             }
    53             for(i=0; i<time; i++)      //遍历排序  ; 
    54             {
    55                 for(j=0; j < time ; j++)
    56                 {
    57                     if(strcmp(ch[i], ch[j]) > 0 )
    58                     sweep(ch[i], ch[j]) ;
    59                 }
    60             } 
    61     
    62              int total = 1 ;   
    63             for(i=1; i<time; i++)//判断不同单词数 ;
    64             if(strcmp(ch[i], ch[i-1]) != 0)
    65             total++ ;
    66             printf("%d
    ", total) ;
    67         }
    68     }
    69     return 0 ; 
    70 }
  • 相关阅读:
    工作五年,后面四年重复着第一年的活儿?
    ECMAScript 6 扫盲
    当前端也拥有 Server 的能力
    简述 OAuth 2.0 的运作流程
    近几年前端技术盘点以及 2016 年技术发展方向
    NodeJS的代码调试和性能调优
    新应用上线 Snippet
    这两天说到的苹果软件中毒是个什么情况?
    网站的SEO以及它和站长工具的之间秘密
    博客搬家通知
  • 原文地址:https://www.cnblogs.com/soTired/p/4666724.html
Copyright © 2011-2022 走看看