"fg how are you lx " 字符串颠倒 "lx you are how fg",单词不变,要求不占用额外的内存空间。

#include<QCoreApplication>

#include<iostream>

#include<algorithm>

usingnamespacestd;

intmain(intargc,char*argv[])

{

QCoreApplicationa(argc,argv);

stringstr="lxgfyouarehow";

reverse(str.begin(),str.end());

intt=0;

for(inti=0;i<str.length();i++)

{

if(str[i]=='')

{

intleft=t,right=i-1;

while(left<right)swap(str[left++],str[right--]);

t=i+1;

}

}

cout<<str;

returna.exec();

}
计算机思维:先打乱信息,然后按照一定规律重组。