将一个英文语句以单词为单位逆序排放。比如“I am a boy”。逆序排放后为“boy a am I”
全部单词之间用一个空格隔开,语句中除了英文字母外。不再包括其它字符。
思路:
先将字符串逆序,然后从左至右扫描。遇到空格。再逆序前面的字符串,直到字符串尾部.
有更简单思路的。欢迎留言讨论.
代码例如以下:
#include <iostream> #include <cstring> using namespace std; void RS(char *bp, char *ep) { while(bp<ep) { char tmp=*bp; *bp=*ep; *ep=tmp; bp++; ep--; } } char * Reverse(char *s) { int len=strlen(s); char *es=s+len-1; RS(s,es); char *bp=s; char *ep=s; while(*ep!='