I am hs----------->hs am I

 1#include<iostream>
 2using namespace std;
 3
 4void Reverse(char *pBegin,char *pEnd){
 5    if (pBegin == NULL || pEnd == NULL)
 6        return ;
 7    while (pBegin < pEnd){
 8        char temp = *pBegin;
 9        *pBegin = *pEnd;
10        *pEnd = temp;
11        pBegin++;
12        pEnd--;
13    }

14}

15
16char *ReverseSentence(char *pData){
17    if (pData == NULL)
18        return NULL;
19    char *pBegin = pData;
20    char *pEnd = pData;
21    while (*pEnd != '\0')
22        pEnd++;
23    pEnd--;
24    Reverse(pBegin,pEnd);
25    pEnd = pData;
26    while (*pBegin != '\0'){
27        if (*pBegin == ' '){
28            pBegin++;
29            pEnd++;
30        }

31        else if (*pEnd == ' ' || *pEnd == '\0'){
32            Reverse(pBegin,--pEnd);
33            pBegin = ++pEnd;
34        }

35        else 
36            pEnd++;
37    }

38    return pData;
39}

40
41int main()
42{
43    char str[] ="I am hs";
44    cout<<str<<endl;
45    cout<<ReverseSentence(str)<<endl;
46    system("pause");
47    return 0;    
48}

posted on 2011-09-14 13:39 Hsssssss 阅读(205) 评论(0)  编辑 收藏 引用 所属分类: C++代码

hs am I" trackback:ping="http://www.cppblog.com/dotaqop/services/trackbacks/155745.aspx" /> -->

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年8月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿

文章分类

文章档案

收藏夹

搜索

最新评论