void reversestring(char* s,int head,int tail){
while(head<=tail){
char temp=s[head];
s[head]=s[tail];
s[tail]=temp;
head++;
tail--;
}
}
char* reverseStr(char* s, int k) {
int ns=0;
while(s[ns]!=0) ns++;
for(int i=0;i<ns;i+=2*k){
if(ns-i>=2*k){
reversestring(s,i,i+k-1);
}else if(ns-i>=k){
reversestring(s,i,i+k-1);
}else{
reversestring(s,i,ns-1);
}
}
return s;
}
结果: