字符个数

Posted Lazy.Cat

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符个数相关的知识,希望对你有一定的参考价值。

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

 

输入

一行字符

输出

统计值

样例输入

aklsjflj123 sadf918u324 asdf91u32oasdf/.‘;123

样例输出

23 16 2 4
#include <stdio.h>
int main()
{
 int letter=0,space=0,number=0,others=0;
 char nextchar;
 for(;nextchar!=\n;)
 {
  scanf("%c",&nextchar);
  if((a<=nextchar&&nextchar<=z)||(A<=nextchar&&nextchar<=Z))
   letter++;
  else if(nextchar== )
   space++;
  else if(0<=nextchar&&nextchar<=9)
   number++;
  else
   others++;
 }
 printf("%d %d %d %d\n",letter,number,space,--others);
    return 0;
}

 

以上是关于字符个数的主要内容,如果未能解决你的问题,请参考以下文章