輸入一行字符,分別統計出包含英文字母、空格、數字和其它字符的個數-簡單題

#include "stdafx.h"
#include<iostream>
using namespace std;
void count(char *c)
{
 if(c==NULL)
  return;
 int zimu=0;
 int shuzi=0;
 int kongge=0;
 int qita=0;
 while(*c)
 {
  if((*c>='a'&&*c<='z')||(*c>='A'&&*c<='Z'))
   zimu++;
  else if(*c==' ')
   kongge++;
  else if(*c>='0'&&*c<='9')
   shuzi++;
  else
   qita++;
  c++;
 }
 cout<<zimu<<endl;
 cout<<kongge<<endl;
 cout<<shuzi<<endl;
 cout<<qita;
 cout<<endl;
}
int main()
{
 char s[100];
 cin.getline(s,100);
 count(s);
 system("pause");
 return 0;
}
相關文章
相關標籤/搜索