zoukankan      html  css  js  c++  java
  • HDUOJ--------Text Reverse

     

    Text Reverse

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13449    Accepted Submission(s): 5140
    Problem Description
    Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.
     
    Input
    The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single line with several words. There will be at most 1000 characters in a line.
     
    Output
    For each test case, you should output the text which is processed.
     
    Sample Input
    3
    olleh !dlrow
    m'I morf .udh
    I ekil .mca
     
    Sample Output
    hello world!
    I'm from hdu.
    I like acm.
    Hint
    Remember to use getchar() to read ' ' after the interger T, then you may use gets() to read a line and process it.

     基础题:

    代码:

     1 #include<iostream>
     2 #define maxn 1005
     3 using namespace std;
     4 char str[maxn][maxn];
     5 int main()
     6 {
     7     int n,i,cnt,j;
     8     char c;
     9     bool ifhave;
    10     //freopen("test.in","r",stdin);
    11     //freopen("teset.out","w",stdout);
    12     scanf("%d",&n);
    13     getchar();
    14     while(n--)
    15     {
    16         j=i=0;
    17         ifhave=false;
    18      while(c=getchar(),c!='
    ')
    19      {
    20          if(c==' ')
    21              j++,i=0;
    22          else
    23             str[j][i++]=c;
    24          
    25      }
    26      if(c==' ')
    27          ifhave=true,j--;
    28      cnt=j;
    29      for(j=0;j<=cnt;j++)
    30      {
    31          for(i=strlen(str[j])-1; i>=0 ; i--)
    32              printf("%c",str[j][i]);
    33             if(j!=cnt) printf(" ");
    34      }
    35      if(ifhave)printf(" ");
    36      puts("");
    37      memset(str,'',sizeof str);
    38     }
    39     return 0;
    40 }

    比较高级的代码:

     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5   int t;
     6   scanf("%d
    ",&t);
     7   while(t--)
     8   {
     9     char s[1005]={};
    10     while(scanf("%[^ 
    ]",s)!=EOF)
    11     {
    12       printf("%s",strrev(s));
    13       s[0]=0;
    14       putchar(getchar());
    15     }
    16   }
    17   return 0;
    18 }
  • 相关阅读:
    libevent简介[翻译]3 前言
    libevent简介[翻译]2 关于异步IO的简单介绍
    gdb调试子进程
    openSUSE Firewalld
    libevent简介[翻译]1 关于这个文档
    构建libevent pdf 文档
    openSUSE编译libevent
    为openSUSE添加源
    .Net Core3.0 WebApi 项目框架搭建 五:仓储模式
    .Net Core3.0 WebApi 项目框架搭建 四:JWT权限验证
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3306347.html
Copyright © 2011-2022 走看看