top1编程
← 返回题目
题解

【入门】统计字母数字空格和其他字符

1 条题解

  • 0
    @ 2026-7-28 22:10:09
    #include<bits/stdc++.h>
    using namespace std;
    string s;long long a,b,c,d;
    int main(){
    	getline(cin,s);
    	for(int i=0;i<s.size();i++){
    		if((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<='z')){
    			a++;
    		}else if(s[i]>='0'&&s[i]<='9'){
    			b++;
    		}else if(s[i]==' '){
    			c++;
    		}else{
    			d++;
    		}
    	}
    	cout<<a<<" "<<b<<" "<<c<<" "<<d;
    	return 0;
    }
    
    • 1