发布网友 发布时间:2024-10-23 23:02
共1个回答
热心网友 时间:2024-11-16 05:52
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int cnt_num = 0;
int cnt_ch = 0;
int cnt_b = 0;
char str[100];
gets(str);
for (int i = 0; i < strlen(str); i++)
{
if (str[i] >= '0' && str[i] <= '9')
cnt_num++;
else if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
cnt_ch++;
else if (str[i] == ' ')
cnt_b++;
}
printf("数字一共有%d个\n",cnt_num);
printf("字母一共有%d个\n",cnt_ch);
printf("空格一共有%d个\n",cnt_b);
return 0;
}