9 solutions

  • 5
    @ 2023-10-5 10:58:11
    #include<bits/stdc++.h>
    using namespace std;
    string n;
    long x;
    int main(){
    	getline(cin,n);
    	int sz=n.size();
    	for(int i=0; i<sz ;i++){
    		if(n[i]==' '){
    			for(int j=i-1;j>=x;j--) cout<<n[j];
    			cout<<' ';
    			x=i+1;
    		}else if(i+1>=sz){
    			for(int j=i;j>=x;j--){
    				cout<<n[j];
    				if(n[j]==n[sz-1]&&x==1) break;
    			}
    		}
    		if(n[i-1]==' '||i==0) x=i;
    	}
    	return 0;
    }
    

    完了,代码写长了

    • 3
      @ 2023-10-28 19:58:10
      #include<iostream>
      #include<string>
      using namespace std;
      int main()
      {
       string a;
       getline(cin,a);//输入
       a+=' ';
       string b="";//获取的单词
       for(int i=0;i<a.length();i++)
       {
        if(a[i]==' ')//是否是单词间隔
        {
         for(int j=b.length()-1;j>-1;j--)//反向输出
         {
          cout<<b[j];
         }
         cout<<" ";//空格!
         b="";
        }
        else
         b+=a[i];//连接当前字符
       }
       return 0;//完结散花!
      }
      
      • 1
        @ 2024-10-11 21:12:31

        如有雷同,纯属巧合

        #include <bits/stdc++.h>
        using namespace std;
        string str;
        int main()
        {
        	while(cin>>str)//不知道要输入多少个
        	{
        		for(int j=str.size()-1;j>=0;j--)//反向输出不必多说
        		{
        			cout<<str[j];
        		}
        		cout<<" ";//因为cin不会获取空格
        	}
        	return 0;
        }
        
        • 1
          @ 2023-12-23 18:36:57

          这个思路很好想的

          #include <bits/stdc++.h>
          using namespace std;
          string s;
          int main(){
          	while(cin>>s){
          		for(int j=s.size()-1;j>=0;j--) cout<<s[j];
          		cout<<" ";
          	}
          	return 0;
          }
          
          • 0
            @ 2024-10-26 16:30:00
            #include<bits/stdc++.h>
            using namespace std;
            int l,r;
            string a;
            int main(){
               getline(cin,a);
               int len=a.length();
               for(int i=0;i<=len;i++){
                  if(a[i]==' '){
                     r=i-1;
                     for(int j=r;j>=l;j--){
                        cout<<a[j];}
                     cout<<' ';
                     l=r+2;}
                  if(a[i]=='\0'){
                     r=i-1;
                     for(int j=r;j>=l;j--){
                        cout<<a[j];}
                     break;}}
               return 0;}
            
            • 0
              @ 2023-10-15 10:59:45
              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
              string s, w[500];
              int wi = 0, b = 0;
              getline(cin, s);
              for(int i = 0; i <= s.length(); ++i)
              {
              if(s[i] == ' ' || s[i] == '\0')
              {
              w[wi++] = s.substr(b, i-b);//截取字符串,从b开始截取i-b个字符
              b = i+1;
              }	
              }
              for(int i = 0; i < wi; ++i)
              {
              reverse(w[i].begin(),w[i].end());//将字符串s前后颠倒
              cout << w[i] <<' ';
              }
              return 0;
              }
              
              
              
              
              
              • 0
                @ 2023-10-9 13:24:07
                #include <bits/stdc++.h>
                using namespace std;
                string s;
                int main(int argc, char **argv){
                	getline(cin,s);
                	int n = 0,len = s.length();
                	for(int i = 0;s[i];i++){
                		if (s[i] == ' '){
                			for(int j = i - 1;j >= i - n;j--){
                				cout << s[j];
                			}
                			printf(" ");
                			n = 0;
                		}else{
                			n++;
                		}
                	}
                	for(int i = len - 1;i >= (len - 1) - n;i--){
                		cout << s[i];
                	}
                	return 0;
                }
                
                • 0
                  @ 2023-10-3 15:20:12
                  using namespace std;
                  string s;
                  int main(){
                  	while(cin >> s){
                  		for(int j = s.size() - 1;j >= 0;j--){
                  			cout << s[j];
                  		}
                  		cout << " ";
                  	}
                  	return 0;
                  }`
                  
                  
                  
                • -1
                  @ 2023-10-3 15:20:05

                  `


                  #include<bits/stdc++.h> using namespace std; string s; int main(){ while(cin >> s){ for(int j = s.size() - 1;j >= 0;j--){ cout << s[j]; } cout << " "; } return 0; }`

                  • 1

                  Information

                  ID
                  630
                  Time
                  1000ms
                  Memory
                  256MiB
                  Difficulty
                  5
                  Tags
                  # Submissions
                  105
                  Accepted
                  43
                  Uploaded By