4 条题解

  • 1
    @ 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;
    }
    
    • 0
      @ 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;
      }
      
      • 0
        @ 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; }

        • 0
          @ 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;
          
          
          }
          
          • 1

          信息

          ID
          73
          时间
          1000ms
          内存
          128MiB
          难度
          5
          标签
          递交数
          511
          已通过
          212
          上传者