4 条题解

  • 3
    @ 2024-7-20 12:00:47
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	string s;
    	getline(cin,s);
    	int i,cnt=0;
    	while(s[i]){
    		if(s[i]!=' ') cnt++;
    		i++;
    	}
    	cout<<cnt;
    	return 0;
    }
    
    • 0
      @ 2025-2-18 19:36:34
      #include <string>
      using namespace std;
      
      int main() {
          string s;
          // 从标准输入读取一行字符串
          getline(cin, s);
          int cnt = 0;
          // 初始化变量 i 为 0
          for (int i = 0; i < s.length(); i++) {
              // 如果当前字符不是空格,则计数器加 1
              if (s[i] != ' ') {
                  cnt++;
              }
          }
          // 输出非空格字符的数量
          cout << cnt;
          return 0;
      }
      
      
      • 0
        @ 2024-7-21 11:04:56

        #include<bits/stdc++.h> using namespace std; int main(){ string s; getline(cin,s); int i,cnt=0; while(s[i]){ if(s[i]!=' ') cnt++; i++; } cout<<cnt; return 0; }

        • -1
          @ 2024-7-21 10:36:29
          #include<bits/stdc++.h>
          using namespace std;
          int main(){
          	string s;
          	getline(cin,s);
          	int i,cnt=0;
          	for(i=0;i<s.size();i++){
          		if(s[i]!=' ') cnt++;
          	}
          	cout<<cnt;
          	return 0;
          }
          • 1

          信息

          ID
          2021
          时间
          1000ms
          内存
          256MiB
          难度
          3
          标签
          递交数
          234
          已通过
          119
          上传者