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了,汗啊。。。。

    还好做出来了

  • 相关阅读:
    检测Linux硬盘IO数据
    获取OrangePI板子CPU温度
    ASP.Net开发WebAPI跨域访问(CORS)的精简流程
    一些常用复合命令
    关于Linux的虚拟内存管理
    Linux中组 与 用户的管理
    linux加载与使用ko驱动
    7z命令行 极限压缩指令
    nodejs的POST请求
    案例:用ajax 方法 解析xml
  • 原文地址:https://www.cnblogs.com/sdutmyj/p/3094058.html
Copyright © 2011-2022 走看看