文章

1

粉丝

503

获赞

0

访问

8.6k

头像
字符个数统计
P1042 重庆大学机试题
发布于2020年3月16日 00:05
阅读数 8.6k

#include <iostream>
#include <string>
using namespace std;
int main()
{
 string str;
 getline(cin, str);
 int a=0, b=0, c=0, d=0;
 int n = str.length();
 for (int i = 0; i < n; i++)
 {
  if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A'&&str[i] <= 'Z'))
   a++;
  else if (str[i] >= '0'&&str[i] <= '9')
   b++;
  else if (str[i] == 32)
   c++;
  else d++;
 }
 cout << a << " " << b << " " << c << " " << d << endl;
 return 0;
}

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发