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. 浅谈PHP5中垃圾回收算法

    原文链接:http://www.cnblogs.com/leoo2sk/archive/2011/02/27/php-gc.html PHP是一门托管型语言,在PHP编程中程序员不需要手工处理内存资源 ...

  2. 正则表达式提取HTML中img标签的src地址

    一般来说一个 HTML 文档有很多标签,比如“”.“”.“”等, 想把文档中的 img 标签提取出来并不是一件容易的事. 由于 img 标签样式变化多端,使提取的时候用程序寻找并不容易. 于是想要寻找 ...

  3. Codeforces D - Ithea Plays With Chtholly

    D - Ithea Plays With Chtholly 思路:考虑每个位置最多被替换c/2次 那么折半考虑,如果小于c/2,从左往右替换,大于c/2总右往左替换,只有小于这个数(从左往右)或者大于 ...

  4. Redis之列表类型命令

    Redis 列表(List) Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素到列表的头部(左边)或者尾部(右边) 一个列表最多可以包含 232 - 1 个元素 (4294967 ...

  5. Failed to execute operation: No such file or directory(systemctl enable iptables.service)

    在保存Iptables配置时:systemctl enable iptables.service 出现错误: Failed to execute operation: No such file or ...

  6. Java类和对象的概念

    Java是一门面向对象的编程语言,理解Java,首先要理解类与对象这两个概念. Java中的类可以看做C语言中结构体的升级版.结构体是一种构造数据类型,可以包含不同的成员(变量),每个成员的数据类型可 ...

  7. php--------使用js生成二维码

    php生成二维码有多种方式,可以在JS中,也可以使用php库,今天写的这个小案例是使用JS生成二维码. 其他方式可以看下一篇文章:php--------php库生成二维码和有logo的二维码 网站开发 ...

  8. 37mysql 表操作

    创建表 #语法: create table 表名( 字段名1 类型[(宽度) 约束条件], 字段名2 类型[(宽度) 约束条件], 字段名3 类型[(宽度) 约束条件] ); #注意: 1. 在同一张 ...

  9. python-day8-字典的内置方法

    # info=['egon','male',18,180,75]### info_dic={'name':'egon','age':18,'sex':'male'} # 有对应关系 # 常用操作:优先 ...

  10. spring AOP自定义注解 实现日志管理

    今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理.废话不多说,直接开始!!! 关于配置我还是的再说一遍. 在appli ...