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;

    }

  • 相关阅读:
    TCP和UDP的区别
    项目--华为商城---登录页面(一)
    Servlet(一)—— 文件上传(表单文件上传)
    LeetCode(一) —— 存在重复
    电脑右击不能创建txt文件
    边工作边刷题:70天一遍leetcode: day 92-2
    自底向上集成 Bottom-Up
    分层集成(线性关系) Layers
    基干集成(内核耦合度高) Backbone
    三明治集成(分而治之策略) 又分为传统型和改进型 Sandwich
  • 原文地址:https://www.cnblogs.com/zhouhongweihpu/p/3256064.html
Copyright © 2011-2022 走看看