思路就是先整体翻转这个句子变为:
won uoy ssim I
任何以单词为单位进行翻转
now you miss I;
以上就是思想,具体代码如下:
// ReverseSentence2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void Reverse(char* pb , char* pe) //将某一段字符串翻转过来
{
char *pl = pb , *pr = pe;
while(pl!=pr&&pl&&pr)
{
char temp = *pl; //不能写成char * temp = pl;否则交换字符的操作失败
*pl = *pr;
*pr = temp;
if(pl+1==pr)break;
pl++;
pr--;
}
}
char* ReverseSentence(char* pData)
{
if(!pData)
return NULL;
char* pb=pData;
char* pe=pData;
while(pe && *pe!='\0')
pe++;
pe--;
Reverse(pb,pe);//翻转整个单词
pb = pe =pData;//指针重新指到句子的头
while (pe && *pe!='\0')
{
while (*pe!='\0'&&pe && *pe!=' ')
pe++;
pe--;
Reverse(pb,pe);
++pe;
while(*pe!='\0'&&*pe==' ')
pe++;
pb=pe;
}
return pData;
}
int _tmain(int argc, _TCHAR* argv[])
{
/*char str[]="abcd";
int len = sizeof(str)/sizeof(char);
Reverse(str,str+len-2);
cout<<str<<endl;*/
char str[]="I miss you now";
cout<<ReverseSentence(str)<<endl;
system("pause");
return 0;
}
程序输出:
分享到:
相关推荐
A:I miss you. B:Fine. Thank you. And you? C:Are you OK? D:This way, please. 17、- Excuse me, can you tell me the way to the bus stop? - _________ A:Yes, go straight down this way to the end. B:...
If you are looking for a good rich text editor on Android, DON'T MISS THIS ONE! It's still in progress now, welcome fork and join me! I published colorpicker and emojipicker as standalone components ...
If you work in a field where math comes with the territory, don't miss the guide that puts a multitude of math solutions right at your fingertips: Mastering Technical Mathematics, Second Edition. ...
so you can add the features into license file if you find the miss. 5, just a fun and for studying,not any commerce... NOTE: The fix only valid running in 32 bit windows , NOT for LINUX or 64 bit ...
Whether you are an Android, iOS, web, or enterprise developer, you do not want to miss the chance that Glass becomes the next big thing. Get started with Beginning Google Glass Development and be ...
After you find a framework file you could pull it via adb pull /path/to/file or use a file manager application. After you have the file locally, pay attention to how Apktool installs it. The number ...
But I'm going to miss you. A. that's too bad B. I'm sorry C. I beg your pardon D. that's great 5.The work is so difficult that we can’t finish it in time ____. A. of our own...
Now you *know* you are protected once and for all! Modular by design! - What comes out?goes back in! What if you change your mind and want to reinstall one of the system components that you ...
* Do you miss some feature? Let us know! * Do you have any troubles? Let us know! Other ways got in touch Unity Forum Thread | Playmaker Thread Follow us Twitter | Facebook | Google+ | LinkedIn ...
There’s much to be learned within these pages and I know you’ll enjoy. –Gary Kelly, CEO and Chairman of Southwest Airlines There are so many parallels between building a great sports team and ...
In a single stroke, the simple sentence cuts through the pervasive tendency students have of getting so close to Zen as to completely miss what it’s all about. An instant teaching on the first page....
A richer conceptualization of "exposure" for epidemiological studies of the "EMF mixture" Bioelectromagnetics Supplement 5:S48^S57 (2001)...epidemiologists might miss something if they measured only 60
A richer conceptualization of "exposure" for epidemiological studies of the "EMF mixture" Bioelectromagnetics Supplement 5:S48^S57 (2001)...epidemiologists might miss something if they measured only 60