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;

    }

  • 相关阅读:
    源码解析之–网络层YTKNetwork
    ARC和非ARC文件混编
    Xcode真机调试中"There was an internal API error"错误解决方法
    设置textView或者label的行间距方法
    iOS中__block 关键字的底层实现原理
    使用AVCaptureSession捕捉静态图片
    使用AVCaptureSession显示相机预览
    短小强悍的JavaScript异步调用库
    开源中国愚人节网页变模糊的js blur代码
    undefined与null的区别
  • 原文地址:https://www.cnblogs.com/zhouhongweihpu/p/3256064.html
Copyright © 2011-2022 走看看