题目1361:翻转单词顺序

来源:互联网 发布:360在线网络测速 编辑:程序博客网 时间:2024/06/05 09:46

http://ac.jobdu.com/problem.php?pid=1361

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int main(){    char str[100000];    while(gets(str))    {    int len,i,j;    len=strlen(str);    reverse(str,str+len);           for(i=j=0;j<len;++j)    {        if(str[j]==' ')        {            reverse(str+i,str+j);            i=j+1;        }         }    reverse(str+i,str+j);    puts(str);    }    return 0;}


0 0
原创粉丝点击