zoukankan      html  css  js  c++  java
  • 单词长度直方图

     1 #define MAXWORDLEN 10
     2 
     3     int FirstWord = 1 ;
     4     int NewWord = 0 ;
     5     int Space =  0 ;
     6     int Doon = 0 ;
     7     int wordlen = 0 ;
     8     char c = 0 ;
     9     char NumberBuf[MAXWORDLEN+1] ;
    10     int thisvalue = 0 ;
    11     int maxvalue = 0 ;
    12     int thisside = 0 ;
    13     int i = 0 ;
    14     for (; i < MAXWORDLEN ; i++)
    15     {
    16         NumberBuf[i] = 0 ;
    17     }
    18     
    19     while (Doon == 0)
    20     {
    21         c = getchar() ;
    22 
    23         if ( c == ' ' ||  c == '\t' || c == '\n' || c == '-' )
    24         {
    25             if(Space == 0)
    26             {
    27                 FirstWord = 0 ;
    28                 Space = 1 ;
    29 
    30                 if(wordlen <= MAXWORDLEN)
    31                 {
    32                     if (wordlen >0 )
    33                     {
    34                         thisvalue = ++NumberBuf[wordlen -1];
    35                         if (thisvalue > maxvalue)
    36                             maxvalue = thisvalue ;
    37                     }
    38                 }else
    39                 {
    40                     thisvalue = ++NumberBuf[MAXWORDLEN] ;
    41                     if (thisvalue > maxvalue)
    42                         maxvalue = thisvalue ;
    43 
    44                 }
    45 
    46                 
    47             }
    48             if(c == '-')
    49                 Doon = 1 ;
    50 
    51         }else
    52         {
    53             if(FirstWord == 1 || Space == 1)
    54             {
    55                 FirstWord = 0 ;
    56                 Space = 0 ;
    57                 wordlen = 0 ;
    58             }
    59             wordlen ++ ;
    60         }
    61         
    62     }
    63     
    64     for (thisvalue = maxvalue ; thisvalue >0 ; thisvalue--)
    65     {
    66         printf("%4d  | ", thisvalue);
    67         for (thisside = 0 ; thisside <= MAXWORDLEN ;thisside++)
    68         {
    69             if (NumberBuf[thisside] >= thisvalue)
    70                 printf("*  ");
    71             else
    72                 printf("   ");
    73         }
    74         printf("\n");
    75     }
    76     printf("      +");
    77     for(thisside = 0; thisside <= MAXWORDLEN; thisside++)
    78     {
    79         printf("---");
    80     }
    81     printf("\n       ");
    82     for(thisside = 0; thisside < MAXWORDLEN; thisside++)
    83     {
    84         printf("%2d ", thisside + 1);
    85     }
    86     printf(">%d\n", MAXWORDLEN);
    87 
    88     system("pause");

     

  • 相关阅读:
    【搜索】棋盘 luogu-3956
    【动态规划】石子合并 luogu-1880
    【动态规划】合唱队形 luogu-
    【模拟】报名签到 luogu-4445
    【排序+贪心】导弹拦截 luogu-1158
    【模拟】不高兴的津津
    【模拟】选数 luogu-1037
    「JOISC2020」建筑装饰 4
    「清华集训」小 Y 和恐怖的奴隶主
    「CF708E」Student's Camp
  • 原文地址:https://www.cnblogs.com/dependence/p/2839106.html
Copyright © 2011-2022 走看看