现在的位置: 首页 > 综合 > 正文

hdu 1062字符串水题

2013年08月23日 ⁄ 综合 ⁄ 共 402字 ⁄ 字号 评论关闭
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int T;
char str[1000];
int begin,end;


int main()
{
    while(scanf("%d",&T)!=EOF)
    {
          getchar();
          for(int i = 1;i <= T; i++)
          { 
                 gets(str);
                 begin = end = 0;
                 while(str[end] != '\0')
                 {
                        if(str[end] == ' ')
                        {
                             for(int j = end-1; j >= begin; j--)
                             {
                                     printf("%c",str[j]);
                                     
                             }
                             printf(" ");
                             begin = end + 1;
                        }
                        end++;
                  
                 }
                 if(str[end] == '\0')
                 {
                             for(int j = end-1; j>= begin; j--)
                             {
                                     printf("%c",str[j]);
                             }
                 }
                 cout<<endl; 
           }
    }
    return 0;
}

抱歉!评论已关闭.