void Reverse(char *p,char *q)
{
    while(p<q)
    {
        swap(*p,*q);
        p++;
        q--;
    }
}
void main()
{

    char s[]="i come from tianjin.";
    char *p=s,*q=s+strlen(s)-1;
    Reverse(p,q);
    p=s;
    q=s;
    while(true)
    {
        if(*q==' ')
        {
            Reverse(p,q-1);
            p=q;
            while(*p!='\0'&&*p==' ')
                p++;
            if(*p=='\0')
                break;
            q=p;
        }
        if(*q=='\0')
        {
            Reverse(p,q-1);
            break;
        }
        q++;
    }

    cout<<"转换后:"<<s<<endl;


    system("pause");
}

 

相关文章:

  • 2021-06-11
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-11-20
  • 2021-05-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2022-02-01
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案