2 条题解

  • 0
    @ 2024-10-5 10:24:43

    #include <bits/stdc++.h> using namespace std; string a; int z=0; int main() { getline(cin,a); a=a+' '; int l=a.length();//length返回字符串的长度; for(int i=0;i<=l+2;i++) { if(a[i]==' ') { for(int j=i-1;j>=z;j--) { cout<<a[j]; } cout<<" "; z=i+1; } } return 0; }

    • 0
      @ 2024-8-24 17:04:00

      string类属于STL,可以用reversebegin()end()函数 另外stringstream用在此处也很方便

      #include <iostream>
      #include <cstring>
      #include <algorithm>
      #include <sstream>
      
      using namespace std;
      
      string str, out, temp;
      
      int main()
      {
          getline(cin, str);
          
          stringstream ssin(str);
          
          while(ssin >> temp) {
              reverse(temp.begin(), temp.end());
              out += temp; out += ' ';
          }
          
          cout << out << endl;
          
          return 0;
      }
      
      • 1

      信息

      ID
      134
      时间
      1000ms
      内存
      128MiB
      难度
      6
      标签
      (无)
      递交数
      114
      已通过
      34
      上传者