zoukankan      html  css  js  c++  java
  • Text Reverse

    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.
    
    
     1 #include<stdio.h>
     2 #include<string.h>
     3 #define N 1010
     4 int main()
     5 {
     6     int n,i,j,m,len;
     7     char st[N]={0};
     8     while(~scanf("%d%*c",&n))
     9     {
    10        while(n--)
    11        {
    12            gets(st);
    13            len=strlen(st);
    14            m=0;
    15            for(i=0;i<=len;i++)
    16            {
    17                if(st[i]==' '||st[i]=='\0')
    18                {
    19                    for(j=i-1;j>=m;j--)
    20                     printf("%c",st[j]);
    21                    if(st[j]!='\0')
    22                     printf(" ");
    23                    m=i;
    24                }
    25            }
    26            printf("\n");
    27        }
    28     }
    29     return 0;
    30 }

    其实这道题想了很久,开始把思维定在用两个数组,当st[j]!=' '时st2[j]=st[j],但是这样不容易实现。今天发现用一个数组就行,循环条件改一下就OK了,汗啊。。。。

    还好做出来了

  • 相关阅读:
    9.算术运算符
    7.字符串格式化
    下载和配置JDK
    Set-常用API及详解
    List-ApI及详解
    电路交换、报文交换、分组交换比较
    集合之List—ArrayList
    java的getClass()函数
    Object类、包装类、内部类详解
    接口的探究
  • 原文地址:https://www.cnblogs.com/sdutmyj/p/3094058.html
Copyright © 2011-2022 走看看