HDOJ/HDU 1062 Text Reverse(字符串翻转~)
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(字符串翻转~)的更多相关文章
- hdu 1062 Text Reverse 字符串
Text Reverse Time L ...
- HDU 1062 Text Reverse(水题,字符串处理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. #include< ...
- 题解报告:hdu 1062 Text Reverse
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write word ...
- 【HDOJ】1062 Text Reverse
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignati ...
- HDU 1062 Text Reverse
题意 : 给出你一个句子,让你把句子中每个单词的字母顺序颠倒一下输出. 思路 : 用栈即可,就是注意原来在哪儿有空格就要输出空格. //hdu1062 #include <iostream> ...
- [hdu 1062] Text Reverse | STL-stack
原题 题目大意: t组数据,每组为一行,遇到空格时讲前面的单词反转输出. 题解: 显然的栈题,遇到空格时将当前栈输出清空即可 #include<cstdio> #include<st ...
- HDOJ 1062 Text Reverse
Text Reverse Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- 1062 Text Reverse
http://acm.hdu.edu.cn/showproblem.php?pid=1062 思路: 最主要的是通过getline函数存取字符串. 如何读取单个单词,并且反向输出? 用\n作为单个单词 ...
- HDOJ/HDU 1073 Online Judge(字符串处理~)
Problem Description Ignatius is building an Online Judge, now he has worked out all the problems exc ...
随机推荐
- Java设计模式--单列设计模式
设计模式:解决某一类问题行知最有效的方法.java有23种设计模式 单列设计模式: 解决一个类在内存中只存在一个对象 思路:(要保证对象的唯一性) 1.为了避免其它程序建立该对象,先禁止替他类创建改对 ...
- 在mipsel-linux平台上的编译应用SQLite-3.5.9
sqlite 第一个Alpha版本诞生于2000年5月,是实现了SQL 92标准的一个大子集的嵌入式数据库,其以在一个库中组合了数据库引擎和接口,能将所有数据存储于单个文件中.官方测试表明sqlite ...
- html复选框多行排列布局
前言:写这篇文章,主要是在于总结一下自己的心得体会... 公司的产品需要实现操作权限配置,我们实现的方式是,左边是“产品”=>“模块”树,右边是由“菜单”和“按钮”复选框按钮.如下图:
- Ajax结合Js操作灵活操作表格
Table页面: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head& ...
- 查看Safari和钥匙串中的密码
Safari Safari的同步书签功能很棒,还可以看到其他设备没关掉的网页.为了省时间,一些经常进的网站,比如博客,邮箱等,我都会选择让Safari保存密码,还使用iCloud同步!因为一直很放心苹 ...
- Constant is not finite! That's illegal. constant:inf'
原本使用正常的情况, 切换为测试库突然出现这个错误, 网上搜索并排查后得出导致这个问题的原因: (1)就是你的除数为0(2)除数或者被除数为null 找出你出错的界面, 并打断点, 看看是否出现上面两 ...
- .NET开源工程推荐(Accord,AForge,Emgu CV)
本人用C#开发了一些项目,下面的开源工程给了我很大的帮助——详细的源代码介绍加丰富的实例运用,是非常不错的学习资源,分享给大家,同时附上我的相关开发项目. Accord.NET The ...
- Jquery 实现瀑布流功能
实现展示地址:http://sandbox.runjs.cn/show/mbojrgag 源码地址:http://runjs.cn/code/qps1jebl 效果截图:
- AS3.0声明静态属性和静态方法
静态属性的变量声明要加static,static var 名称:属性类型=值 静态属性的常量声明要加static或者const,并在声明时就要赋值.static||const var 名称:属性类型= ...
- CentOS6.5 yum安装桌面环境
安装原因 安装centos6.5时选择了minimal CentOS最小化安装方式 需要使用浏览器拨号连接内网 安装过程 通过yum grouplist查询在 group 软件包中,Desktop.D ...