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.

题意:

输入一行字符串,将每一个单词(只有空格隔开)倒序输出!

注意:

开始和结尾可能有多个空格,单词之间可能有多个空格!

PE的请注意:空格必须照原样输出!有几个输出几个,不能多输出也不能少输出!

import java.util.Scanner;

/**
* @author 陈浩翔
* 2016-5-25
*/
public class Main{ public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t =sc.nextInt();
sc.nextLine();//读取输入t之后的回车
while(t-->0){
String str=sc.nextLine();
String s[] = str.split(" ");
String str2="";
for(int i=0;i<s.length;i++){
for(int k=s[i].length()-1;k>=0;k--){
System.out.print(s[i].charAt(k));
str2+=s[i].charAt(k);
}
if(i!=s.length-1){
System.out.print(" ");
str2+=" ";
}
}
for(int i=str2.length();i<str.length();i++){
System.out.print(" ");
} System.out.println();
}
}
}

HDOJ/HDU 1062 Text Reverse(字符串翻转~)的更多相关文章

  1. hdu 1062 Text Reverse 字符串

    Text Reverse                                                                                  Time L ...

  2. HDU 1062 Text Reverse(水题,字符串处理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. #include< ...

  3. 题解报告:hdu 1062 Text Reverse

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write word ...

  4. 【HDOJ】1062 Text Reverse

    Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignati ...

  5. HDU 1062 Text Reverse

    题意 : 给出你一个句子,让你把句子中每个单词的字母顺序颠倒一下输出. 思路 : 用栈即可,就是注意原来在哪儿有空格就要输出空格. //hdu1062 #include <iostream> ...

  6. [hdu 1062] Text Reverse | STL-stack

    原题 题目大意: t组数据,每组为一行,遇到空格时讲前面的单词反转输出. 题解: 显然的栈题,遇到空格时将当前栈输出清空即可 #include<cstdio> #include<st ...

  7. HDOJ 1062 Text Reverse

    Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  8. 1062 Text Reverse

    http://acm.hdu.edu.cn/showproblem.php?pid=1062 思路: 最主要的是通过getline函数存取字符串. 如何读取单个单词,并且反向输出? 用\n作为单个单词 ...

  9. HDOJ/HDU 1073 Online Judge(字符串处理~)

    Problem Description Ignatius is building an Online Judge, now he has worked out all the problems exc ...

随机推荐

  1. 网页版 treeview使用中遇到的问题

    <div class="ScrollBar" id="ItemsTree"></div> var cla = $("#Item ...

  2. 《你不常用的c#之三》:Action 之怪状

    转载自csdn:http://blog.csdn.net/robingaoxb/article/details/6199891 例1:   public static void Main() { Li ...

  3. 'EntityValidationErrors' property for more details

    很多小猿遇到这个Exception 的时候,都会有点无厘头.这个时候最好try-- catch下,找到出错的地方.本人习惯在页面上加个lable标签,把exc msg(exception messag ...

  4. AcroExch.Rect 单位、属性问题

    AcroExch.Rect  有四个属性:Top,Right,Left,Buttom 1.单位:point,一般通过英寸换算,1point=1/72 inch(英寸) 2.属性:Top: 区域距离 x ...

  5. 前端--json数据的处理及相关兼容问题

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...

  6. ubuntu亮度无法自动调节终极解决方案

    友情链接:IT狂人博客 这个问题纠结了我快两年,主要是自己懒,写了个脚本来调节亮度,不过还是稍显不便.近日兴起折腾了一番,终于找到问题根结了. There are many ways to contr ...

  7. highcharts时间图

    这篇文章适合对highcharts已经有一定了解的猿友. 前两天想用highcharts做一个时间图,但是时间轴(x轴)的时间坐标并不是等间隔的,之前一直采用的方法是把时间做成等间隔的,然后没有数据的 ...

  8. python隐含的特性

    本文源自(http://stackoverflow.com/questions/101268/hidden-features-of-python)希望介绍Python非常有用,而比较忽视的Python ...

  9. runas /user:administrator cmd 以管理员身份运行CMD

    runas /user:administrator cmd 以管理员身份运行CMD 1.windows+r打开 2.然后根据提示输入密码

  10. SSD: Single Shot MultiBox Detector

    By Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexande ...