#include<iostream>
#include<algorithm>
using namespace std;
char* Overturn(char *c,int n) {
if (c == NULL || n <= 0) return NULL;
int i = 0, j = n - 1;
while (i<j) swap(c[i++],c[j--]);
int p = 0,q = 0;
while (c[q]!='\0'){
while (c[q + 1] != '\0' && c[q + 1] != ' ') q++;
int i = q;
while (p <= i) swap(c[p++],c[i--]);
if(c[++q]!='\0') p = q + 1;
}
return c;
}
int main() {
char p[] = "i am a student.";
cout<<Overturn(p,15)<<endl;
return 0;
}
剑指offer58题目一
最新推荐文章于 2021-10-20 21:25:41 发布