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;

    }

  • 相关阅读:
    React 构建方法总结
    集思广益 (一)
    C#方法调用
    C# Hello World 实例
    C# 环境
    C# 简介
    对象类型的本地写入---plist文件创建以及读取
    正则判断 手机邮箱的正确格式
    数组去重
    Base64编码
  • 原文地址:https://www.cnblogs.com/zhouhongweihpu/p/3256064.html
Copyright © 2011-2022 走看看