#include <iostream>
using namespace std;

int main() {
    int count=0;
    char a;
    while (cin.get(a)) { // 注意 while 处理多个 case
        if(a ==' '){
            count=0;
        }else if(a=='\n'){
            break;
        }else{
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
} 
// 64 位输出请用 printf("%lld")

注意

  1. 输入使用cin.get(a), 而不是cin>> a ;会吃掉空格引发报错;
  2. 句尾有'\n'记得处理,不然会计入其中