zoukankan      html  css  js  c++  java
  • 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();
        }
    
    }
  • 相关阅读:
    存储过程参数不能使用函数
    .gitignore git已跟踪文件不生效
    Css选择器-层次选择器(关系选择器)
    Mysql自定义变量的作用
    jQuery 鼠标滑过Div变色
    DataTable导出excel 设置单元格格式
    layui table 详细讲解
    npm 常用命令详解
    SQL Server 2008下轻松调试T-SQL语句和存储过程
    帆软报表常用功能
  • 原文地址:https://www.cnblogs.com/watchfree/p/5308159.html
Copyright © 2011-2022 走看看