单词翻转c++

昨天一个学长大佬交了我们sort排序。个人感觉还挺好的,代码也不难。学长着实厉害,希望未来也能成为像他们一样的人。


 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {   int x=-1;
 5     bool flag=0;
 6     char a[555],b[251],c[521];
 7     cin.getline(a,555);
 8     for(int i=0;i<=strlen(a);i++)
 9     {   flag=0;
10         if(a[i]==' '  || a[i]=='\0')
11         {
12          
13         if(a[i-1]!=' ')
14         {
15             for(int j=i-1;j>=x+1;j--)
16             {
17             cout<<a[j];
18             }
19             cout<<" ";
20         }
21         else cout<<" "; 
22         x=i; 
23         }
24     }
25 }
26  
View Code

 

        }
        else cout<<" "; 
        x=i; 
		}
    }
}
 

  

posted @ 2018-06-27 18:50  CJjiqirenqiu  阅读(371)  评论(0编辑  收藏  举报