注册 登录
编程论坛 C++教室

麻烦解释一下这道程序

cwzxwwy 发布于 2012-05-16 11:56, 327 次点击
#include <iostream>
using namespace std;
int main()
{int upper=0,lower=0,digit=0,space=0,other=0,i=0;
char *p,s[200];
cout<<"input string:";
while ((s[i]=getchar())!='\n') i++;
p=&s[0];               
while (*p!='\n')
  {if (('A'<=*p) && (*p<='Z'))
     ++upper;
   else if (('a'<=*p) && (*p<='z'))
     ++lower;
   else if (*p==' ')
     ++space;
   else if ((*p<='9') && (*p>='0'))
     ++digit;
   else
     ++other;
   p++;
  }
cout<<"upper case:"<<upper<<endl<<"lower case:"<<lower<<endl;
cout<<"space:"<<space<<endl<<"digit:"<<digit<<endl<<"other:"<<other<<endl;
return 0;
}
2 回复
#2
yuccn2012-05-19 11:50
cout<<"upper case:"<<upper<<endl<<"lower case:"<<lower<<endl;
 cout<<"space:"<<space<<endl<<"digit:"<<digit<<endl<<"other:"<<other<<endl;
 
如果这个信息给你,你都要人家帮你解析这个函数,你就要好好反省一下了。
#3
邋遢鬼2012-05-30 11:22
统计输入的字符串中数字,大写字母,小写字母,空格,以及别的比如标点等的个数。
1