top1编程
← 返回题目
题解

【入门】统计字符的个数

1 条题解

  • 0
    @ 2026-7-29 20:22:24
    // 读取题目给出的数据。
    // 按照题意完成计算。
    // 输出最终答案。
    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        char s[25];
        cin.getline(s, 25);
        int da = 0, xiao = 0, shu = 0;
        for(int i = 0; s[i] != &#39;&#92;0&#39;; i++){
            if(s[i] == &#39;#&#39;){
                break;
            }
            if(s[i] >= &#39;A&#39; && s[i] <= &#39;Z&#39;){
                da++;
            }
            else if(s[i] >= &#39;a&#39; && s[i] <= &#39;z&#39;){
                xiao++;
            }
            else if(s[i] >= &#39;0&#39; && s[i] <= &#39;9&#39;){
                shu++;
            }
        }
        cout << da << " " << xiao << " " << shu;
        return 0;
    }
    
    • 1