川川好久没发文了
原题:
用赋初值的方法把字符串 “ C is a general purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.” 存放到字符数组s中,编程统计其中的大写字母、小写字母、数字、空格、逗号的个数。
代码:
using namespace std;
int main()
{
char c;
int smallletters = 0, largeletters=0,space = 0, digit = 0,douhao=0, other = 0;
cout << "请输入字符串:";
while ((c = getchar()) != '\n')
{
if (c >= 'a' && c <= 'z')
{
smallletters++;
}
else if (c >= 'A' && c <= 'Z')
{
largeletters++;
}
else if (c == ' ')
{
space++;
}
else if (c >= '0' && c <= '9')
{
digit++;
}
else if (c == ',')
{
douhao++;
}
else
{
other++;
}
}
cout <<"小写字母:"<< smallletters <<"\t"<<"大写字母:"<<largeletters<<"\t"<<"空格:"<< space <<"\t"<<"数字:"<< digit <<"\t"<<"逗号:"<<douhao<<"\t"<<"其它:"<< other <<"\t"<< endl;
return 0;
}