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 '\n' 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();
} }

1.2.2 Text_Reverse的更多相关文章

随机推荐

  1. win10 操作系统 修改桌面图标

    桌面右击出现菜单后,点击个性化: 点击左边菜单的主题,点击桌面图标设置,在新窗口中选择需要显示的图标接口 details please check following screenshot

  2. [ios][map]自定义地图标注

    参考:http://blog.csdn.net/mad1989/article/details/8794762 ios 一步一步学会自定义地图吹出框(CalloutView)-->(百度地图,高 ...

  3. 关于python中的 “ FileNotFoundError: [Errno 2] No such file or directory: '……'问题 ”

    今天在学python时,在模仿一个为图片加上图标并移动到指定文件夹的程序时遇到“FileNotFoundError: [Errno 2] No such file or directory: '152 ...

  4. Linux下Tomcat启动设置debug模式启动

    原文: https://blog.csdn.net/li295214001/article/details/42077247 https://blog.csdn.net/jackie_xiaonan/ ...

  5. ubuntu server 无线网卡的处理

    1) iwconfig 确定一下接口的名称 2) 编辑 /etc/network/interfaces 加入下面的代码 auto wlan0 iface wlan0 inet dhcp wpa-ssi ...

  6. [Java学习] Java多态和动态绑定

    在Java中,父类的变量可以引用父类的实例,也可以引用子类的实例. 请读者先看一段代码: 1. public class Demo { 2. public static void main(Strin ...

  7. docker on mac:误删default vm的处理方法

    通过docker-machine 重新建一个vm,在virtualbox里可以直接看到多出来一个vm docker-machine create --driver virtualbox default

  8. Python的第二次作业

    羊车门问题 1.我认为 会 增加选中汽车的机会,原因如下: 不换的情况:对于参赛者而言无论选哪一扇门都有1/3的几率能获得车子. 换的情况  :对于参赛者而言,有两种情况「1.参赛者第一次就选择到了正 ...

  9. AIX的iostat命令解析(翻译红皮书)

    1.确定磁盘使用率 $ iostat -T 2 10System configuration: lcpu=8 drives=29 paths=52 vdisks=0tty:      tin      ...

  10. Asterisk——part 1

    Asterisk Russell Bryant Asterisk1 is an open source telephony applications platform distributed unde ...