5 条题解

  • 0
    @ 2025-3-5 12:14:46
    a=str(input())
    b=len(a)
    c=[]
    e=''
    for i in range(0,b):
        c.append(str(a[i]))
        if c[i]!=" ":   
            e+=c[i]
    print(e)
    print(len(e))
    
  • -3
    @ 2023-7-17 19:59:37
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    
    int main()
    {
        string a;
        getline(cin,a);
        int cnt=0;
        for(int i=0;i<a.length();i++)
        {
            if(a[i]==' ')
            {
    
                continue;
            }
            cout<<a[i];
            cnt++;
        }
        cout<<endl<<cnt;
        return 0;
    }
    
    • -3
      @ 2023-7-10 9:16:24

      短小精悍 #include <bits/stdc++.h> using namespace std; int main() { char n; int i=1,t=0; while(cin>>n) { if(n!=' ') { cout<<n; t++; } } cout<<"\n"<<t; return 0; }

      • -3
        @ 2023-1-13 15:08:39
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        
        string a;
        int n = 0;
        while (cin >> a)
        {
        n = n + a.size();
        for (int b = 0; b <= a.size() - 1; b++)
        {
        
        cout << a[b];
        
        }
        
        }
        cout << endl;
        cout << n;
        
        
        }
        
        • -3
          @ 2022-11-23 10:47:15

          注意有空格的字符串的读取要用getline 以及string的遍历可以用auto(需C++11)

          #include <bits/stdc++.h>
          using namespace std;
          
          int main()
          {
          	int cnt = 0;
          	string s;
          	getline(cin,s);
          	for(auto x:s)
          	{
          		if(x!=' ') cout << x;
          		else cnt++;
          	}
          	cout << endl << s.length()-cnt;
          	return 0;
          }
          
          • 1

          信息

          ID
          73
          时间
          1000ms
          内存
          128MiB
          难度
          4
          标签
          递交数
          612
          已通过
          273
          上传者