HDU 1062 Text Reverse

来源:互联网 发布:java获取昨天时间戳 编辑:程序博客网 时间:2024/04/27 16:04

字符串的倒置,注意字符串接受和个别细节就ok了,接受cas的时候,下面接受字符用getchar()接受换行符,否则换行符会当输入数据接收的。

 

#include <iostream>#include <cstdio>#include <cstring>#define nMax 1024using namespace std;string s1;char s[nMax];char c;int main(int argc, char *argv[]){    int cas,j=0;    scanf("%d",&cas);    getchar();    while(cas--)    {        while(scanf("%c",&c)&&c!='\n')        {            if(c==' ')            {                int len=j;                for(int i=len-1; i>=0; i--)                {                    printf("%c",s[i]);                }                printf(" ");                j=0;            }            else            {                s[j++]=c;            }                    }        int len=j;        for(int i=len-1; i>=0; i--)        {            printf("%c",s[i]);        }        printf("\n");        j=0;    }        return 0;}


 

原创粉丝点击