/*
题目:
将字符串的前sep个字符转移到字符串尾部。
*/
/*
思路:
更好的方法:
先翻转前sep个字符,再翻转后面的字符,最后全体翻转。
*/
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
void verse(char* pBegin,char* pEnd){
while(pEnd > pBegin){
char temp = *pBegin;
*pBegin = *pEnd;
*pEnd = temp;
pBegin++;
pEnd--;
}
}
char* ReverseSentence(char* pData,int sep){
char* pBegin = pData;
char* pEnd = pData;
int length = 0;
while(*pEnd != '\0'){
pEnd++;
length++;
}
if(sep > length) return nullptr;
pEnd--;
verse(pBegin,pBegin+sep-1);
verse(pBegin+sep,pEnd);
verse(pBegin,pEnd);
return pData;
}
int main(){
char pData[] = "abcdefg";
char* res = ReverseSentence(pData,2);
while(*res != '\0'){
cout<<*res;
res++;
}
}