• 1.2.2 Text_Reverse


    Text Reverse 

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)  

    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.

       

    import java.util.Scanner;
    public class Main {
        static String reverseStr(String str){
            StringBuffer buf=new StringBuffer();
            buf.append(str);
            return buf.reverse().toString();
            
        }
        public static void main(String [] args){
            Scanner sc=new Scanner(System.in);
            int t=sc.nextInt();
            sc.nextLine();
            while(t-->0){
                String str1=sc.nextLine();
                String str[]=str1.split(" ");
                for(int i=0;i<str.length;i++){
                    System.out.print(reverseStr(str[i]));
                    if(i<str.length-1)
                        System.out.print(" ");
                }
                if(str1.endsWith(" "))System.out.print(" ");  ////尤其注意这里,表示最后一个字符后可能有空格  
                System.out.println();
            
            }
            sc.close();
        }
    
    }
  • 相关阅读:
    js 数组方法比较
    js 知识点
    vuex、redux、mobx 对比
    读SRE Google运维解密有感(二)
    读SRE Google运维解密有感(一)
    001_深度剖析什么是 SLI、SLO和SLA?
    006_mac osx 应用跨屏幕
    005_ss-link.info的ping探测工具
    015_sublime插件管理及所有非常有用插件
    001_软件waf
  • 原文地址:https://www.cnblogs.com/watchfree/p/5308159.html
Copyright © 2020-2023  润新知