作业:
#include <iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
string str;
// array<char,128> a;
// array<char,128>::iterator iter;
cout << "请输入一个字符串:" << endl;
getline(cin,str);
int b = str.size();
// char *p=(char *)&str;
// for(int j=0;j<b;j++)
// {
// cout << *(p+j);
// }
int big=0,little=0,num=0,blank=0,other=0;
for(int i=0;i<b;i++)
{
if(str.at(i)>='A' && str.at(i)<='Z')
{
big++;
continue;
}
if(str.at(i)>='a' && str.at(i)<='z')
{
little++;
continue;
}
if(str.at(i)>=0 && str.at(i)<=9)
{
num++;
continue;
}
if(str.at(i)==' ')
{
blank++;
continue;
}
else
{
other++;
continue;
}
}
cout << "big =" << big << endl;
cout << "little =" << little << endl;
cout << "num =" << num << endl;
cout << "blank =" << blank << endl;
cout << "other =" << other << endl;
return 0;
}
思维: