void reverse_string(char* s,int head,int tail){
while(head<=tail){
char t=s[head];
s[head]=s[tail];
s[tail]=t;
head++;
tail--;
}
}
char* reverseStr(char* s, int k) {
int ssize=0;
while(s[ssize]!=0) ssize++;
for(int head=0;head<ssize;head+=2*k){
if(ssize-head<=k){
reverse_string(s,head,ssize-1);
}else{
reverse_string(s,head,head+k-1);
}
}
return s;
}
结果:
标签:head,int,反转,II,541,字符串 From: https://www.cnblogs.com/llllmz/p/18042349