1 solutions

  • 0
    @ 2024-6-13 15:41:59

    模拟(O(n)O(n))

    • 从前往后遍历每个字符,过滤对应的空白字符
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        string s;
        getline(cin,s); //获取包含空白字符的字符串
        int cnt=0;
        for(char x:s) //枚举每个字符
        {
            if(x==' ') continue; //不统计空格
            cnt++;
        }
        cout<<cnt;
        return 0;
     } 
    
    • 1

    Information

    ID
    1059
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    4
    Accepted
    3
    Uploaded By