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;

    }

  • 相关阅读:
    SublimeText4 相比3的更新亮点与安装
    [原创]产品和成本效率总结提炼
    [原创]企业的生命周期总结提炼
    [原创]从不确定到确定性总结提炼
    [原创]验证需求(需求三角)总结提炼
    [原创] Test Card 模型用于验证商业 Idea(想法)总结提炼
    [原创]精益画布(lean canvas)总结提炼
    [原创]商业画布( Business Model Generation)总结提炼
    [原创]总结常见获客渠道
    [原创]什么是增长总结提炼
  • 原文地址:https://www.cnblogs.com/zhouhongweihpu/p/3256064.html
Copyright © 2011-2022 走看看