在这里插入图片描述

#include<iostream>
#include<string>
using namespace std;
int main() {
	string str;
	int letter=0,space=0,digit=0,other=0;
	getline(cin,str);
	for(int i=0; i<str.length(); i++) {
		if(str[i]>=48&&str[i]<=57) digit++;
		else if(str[i]>='A'&&str[i]<='Z'||str[i]>='a'&&str[i]<='z') letter++;
		else if(str[i]==32) space++;
		else other++;
	}
	cout<<letter<<' '<<space<<' '<<digit<<' '<<other<<endl;
}

更多推荐