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. [Jquery] jQuery.cookie帮助类 (转载)

    /** * Cookie plugin * * Copyright (c) [url=http://sufei.cnblogs.com/]http://sufei.cnblogs.com[/url] ...

  2. mysql的账户失效,之前的密码无法登录

     引用自:http://blog.sina.com.cn/s/blog_682c287b0100ofz8.html 此为linux服务器下的做法 方法一: 1.关闭mysql    # service ...

  3. 阿里云服务器(Win 2008 R2 Standard)安装MSSM 2008 R2之1033和2052问题

    最近在给租用的阿里云服务器安装Sql Server 2008 R2 Express时,遭遇下面的问题.经过几番折腾后,终于解决问题,完成安装,这里总结分享我的解决方法,希望能给遇到相同问题的小伙伴们节 ...

  4. OC基础-day04

    #pragma mark -  Day04_01_匿名对象 1. 如果函数有返回值 我们可以不使用变量接收返回值. 而是直接将函数写在要使用其返回值的地方. 2. 正常情况下.我创建对象. 是使用了1 ...

  5. 如何在cmd中运行数据库

    在开始菜单中输入cmd 在控制板输入:net  start  MSSQLserver 启动数据库 在控制板输入:net  stop  MSSQLserver 关闭数据库 在控制板输入:net  pur ...

  6. CSS Outlines

    轮廓(outline)是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用. 轮廓(outline)属性指定了样式,颜色和外边框的宽度. 轮廓(outline)实例 在元素周围画线本例演 ...

  7. ScheduleThreadPoolExecutor源码分析

    ScheduleThreadPoolExecutor源码分析(一) Java中ScheduleThreadPoolExecutor主要用于执行延迟任务或者按照一定的频率执行任务.其中scheduleA ...

  8. IE6 for WIN8

    分享一款微软原生内核的Ie6,绿色免安装,无广告,无插件. 点击下载IE6 for WIN8 来源:子涵的博客

  9. javascript 不间断向左滚动图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. 计算机视觉的matlab工具箱及MVG等

    MATLAB Functions for Multiple View Geometry Peter Kovesi's Matlab functions for Computer Vision Jean ...