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

    还好做出来了

  • 相关阅读:
    线段树时间分治
    CDQ分治
    并查集练习
    hihocoder 1513 小Hi的烦恼 (bitset优化)
    线段树维护哈希
    使用swift语言进行IOS应用开发
    用jquery+Asp.Net实现省市二级联动
    苹果IOS与谷歌 android系统的UI设计原则
    优秀设计师应当知道的20大UI设计原则
    JQuery Easy Ui dataGrid 数据表格
  • 原文地址:https://www.cnblogs.com/sdutmyj/p/3094058.html
Copyright © 2011-2022 走看看