zoukankan      html  css  js  c++  java
  • 1012: C语言程序设计教程(第三版)课后习题6.2

    题目描述

    输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。

    输入

    一行字符

    输出

    统计值

    样例输入

    aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
    

    样例输出

    23 16 2 4

     1 #include "stdio.h"
     2 
     3 int main(int argc, char const *argv[])
     4 {
     5     char s[81];
     6     int i, char_count = 0, num_count = 0, space_count = 0, other_count = 0;
     7     // scanf("%s", s);
     8     gets(s);
     9 
    10     for(i = 0; s[i] != ''; i++)
    11     {
    12         if(s[i] >= 'A' && s[i] <= 'Z' || s[i] >= 'a' && s[i] <= 'z')
    13             char_count ++;
    14         else if(s[i] >= '0' && s[i] <= '9')
    15             num_count ++;
    16         else if(s[i] == ' ')
    17             space_count ++;
    18         else
    19             other_count ++;
    20     }
    21 
    22     printf("%d %d %d %d
    ", char_count, num_count, space_count, other_count);
    23     return 0;
    24 }
  • 相关阅读:
    NumPy
    NumPy切片和索引
    NumPy来自数值范围的数组
    NumPy来自现有数据的数组
    NumPy数组创建例程
    NumPy数组属性
    hdu 1072 Nightmare
    hdu 1010
    nyoj zb的生日
    Catch That Cow
  • 原文地址:https://www.cnblogs.com/hello-lijj/p/7827640.html
Copyright © 2011-2022 走看看