`
java-mans
  • 浏览: 11459947 次
文章分类
社区版块
存档分类
最新评论

给出"I miss you now"输出"now you miss I"

 
阅读更多

思路就是先整体翻转这个句子变为:

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


程序输出:

分享到:
评论

相关推荐

    2012英语资料

    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:...

    Android代码-are

    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 ...

    Mastering Technical Mathematics 2nd Edition

    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. ...

    AnsoftDesignerV6win32crack

    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 ...

    Beginning Google Glass Development

    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 ...

    apktool documentation

    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 ...

    八年级下学期期末考试英语试题.doc

     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...

    xplite_trial

    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 ...

    IOS Native 8.4

    * 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 ...

    Great.Teams.16.Things.High.Performing.Organizations.Do.Differently.epub

    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 ...

    Zen Mind, Beginner's Mind 英文版

    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....

    对“EMF 混合物”的流行病学研究的“暴露”的更丰富的概念化

    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"

    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

Global site tag (gtag.js) - Google Analytics