zoukankan      html  css  js  c++  java
  • -hdu-1062-Text Reverse

    Text Reverse

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 13276    Accepted Submission(s): 5065

    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.

     

     

    解题思路:

    把单词倒叙输出即可;也可以用  strrev 函数。

    程序代码:

    #include<stdio.h>

    #include<string.h>

    int main()

    {

        int n,len1,k,i,j,m;

        char a[1100],b[1100];

        while(scanf("%d",&n)!=EOF)

        {

            getchar();

            while(n--)

            {

                gets(a);

                len1=strlen(a);

                m=0;

                k=0;

                for(i=0;i<=len1;i++)

                {

                 

                   

                    if(a[i]==' '||a[i]=='')      // 判断是否为空格  但是最后一位  是    

                    {

                        for(j=i-1;j>=k;j--)

                        {

                            printf("%c",a[j]);

                            //b[m]=a[j];

                            //m++;

                        }

                        k=i+1;

                        if(i!=len1)

                        printf(" ");

                    }

                   

                }

               puts("");

               //printf("%c%d%c",'p',' ','p');

            }

           

        }

        return 0;

    }

  • 相关阅读:
    Linux常用的命令
    Docker编写镜像 发布个人网站
    Linux安装docker笔记
    单例模式
    Cache一致性协议之MESI
    linux环境搭建单机kafka
    【Ray Tracing The Next Week 超详解】 光线追踪2-4 Perlin noise
    【Ray Tracing The Next Week 超详解】 光线追踪2-3
    【Ray Tracing The Next Week 超详解】 光线追踪2-2
    【Ray Tracing The Next Week 超详解】 光线追踪2-1
  • 原文地址:https://www.cnblogs.com/zhouhongweihpu/p/3256064.html
Copyright © 2011-2022 走看看