剑指offer58题目一

#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;
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页