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. 搭建linux环境下jenkins可移植环境

    1:背景 项目领域:android. 项目需求为:建立一个网站用于产品经理(以下称为PM)配置该apk所需服务插件,打包出包(包含:apk,文档,demo等等)给厂商并且记录打包出包等信息. 项目设计 ...

  2. Android- Context理解

    学习了安卓以后还是不理解Context的用法:Api文档链接http://wear.techbrood.com/reference/android/content/Context.html 一个非常好 ...

  3. .NET性能优化方面的总结

    从2004年底开始接触C#到现在也有2年多的时间了,因为有C++方面的基础,对于C#,我习惯于与C++对比.现在总结一些.NET方面的性能优化方面的经验,算是对这两年多的.NET工作经历的总结.    ...

  4. 关于基于.net的WEB程序开发所需要的一些技术归纳

    前提: 最近公司里有一个同事,年龄比我大几岁,但是由于是转行来做开发的,许多的关于.net开发技术不是很入行,所以总是会问我一些东西,基于自己以前的一些 经验,总是会愿意给他讲一些总结性的东西,希望他 ...

  5. Apache虚拟目录

    Apache虚拟目录  1.打开Apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#! 2.在httpd.conf 末尾 ...

  6. C#输出40以内的所有奇数程序代码

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  7. 利用SpringMVC参数绑定实现动态插入数据

    javabean代码:public class User { private String firstName; private String lastName; public String getF ...

  8. CSAPP Lab2: Binary Bomb

    著名的CSAPP实验:二进制炸弹 就是通过gdb和反汇编猜测程序意图,共有6关和一个隐藏关卡 只有输入正确的字符串才能过关,否则会程序会bomb终止运行 隐藏关卡需要输入特定字符串方会开启 实验材料下 ...

  9. TCP/IP笔记 应用层(2)——FTP

    1. FTP(File Transfer Protocol) 文件传送协议 FTP 只提供文件传送的一些基本的服务,它使用 TCP 可靠的运输服务.FTP 的主要功能是减少或消除在不同操作系统下处理文 ...

  10. WPF Window异形窗口演示

    我们先通过简单的效果展示,切换展示不同图片: 我们先定义图片资源文件,我们可以在window资源中定义,下面的在app.xaml文件来定义: <Application x:Class=" ...