zoukankan      html  css  js  c++  java
  • hdu 2027统计元音

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2027

    思路:主要考察gets()函数用法,能够接受输入的空格,如果用%s或是cin>>str都不能输入空格

     1 #include <cstdio>  
     2 #include <iostream>  
     3 #include<algorithm>
     4 #include<math.h> 
     5 #include <string.h>  
     6 #include<queue>
     7 using namespace std;
     8 
     9 int main()
    10 {
    11     int a,e,i,o,u;
    12     int num;
    13     char str1[105];
    14     while(scanf("%d",&num)!=EOF)
    15     {
    16         getchar();            //吸收回车 
    17         for(int j=0;j<num;j++)
    18         {
    19             memset(str1,'',sizeof(str1)); 
    20             a=e=i=o=u=0;
    21             gets(str1);      //gets可以读入空格 
    22         
    23             for(int j=0;j<strlen(str1);j++)
    24             {
    25                 if(str1[j] == 'a')
    26                     a++; 
    27                 else if(str1[j] == 'e')
    28                     e++;
    29                 else if(str1[j] == 'i')
    30                     i++;
    31                 else if(str1[j] == 'o')
    32                     o++;
    33                 else if(str1[j] == 'u')
    34                     u++;
    35             }
    36             if(j == num-1)
    37             {
    38                 printf("a:%d
    ",a);
    39                 printf("e:%d
    ",e);
    40                 printf("i:%d
    ",i);
    41                 printf("o:%d
    ",o);
    42                 printf("u:%d
    ",u);
    43             }
    44             else
    45             {
    46                 printf("a:%d
    ",a);
    47                 printf("e:%d
    ",e);
    48                 printf("i:%d
    ",i);
    49                 printf("o:%d
    ",o);
    50                 printf("u:%d
    
    ",u);
    51             }
    52         } 
    53     }
    54     return 0;
    55 }  
  • 相关阅读:
    构造函数、原型、实例化对象
    JS闭包的理解
    JQuery知识点
    面向对象
    学习使用Vuex
    Runtime详解
    ffmpeg各结构体之间关联 ---- AVPacket
    AVFrame
    block的底层原理
    performSelector
  • 原文地址:https://www.cnblogs.com/pter/p/4988979.html
Copyright © 2011-2022 走看看