HDOJ/HDU 1062 Text Reverse(字符串翻转~)
2016-05-25 16:53
351 查看
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的请注意:空格必须照原样输出!有几个输出几个,不能多输出也不能少输出!
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(); } } }
相关文章推荐
- uva 10553 Treasure Map
- vim配置及插件安装管理(超级详细)
- poj 3368 (线段树pascal)
- matlab图像处理基础知识0(双线性插值matlab实现--调整水平和垂直放大倍数)
- HDOJ/HDU 1062 Text Reverse(字符串翻转~)
- leetcode.138. Copy List with Random Pointer
- 数据清洗的一些梳理
- python爬取当前汇率,jython的应用,实时汇率兑换
- 为什么程序员需要关心顺序一致性(Sequential Consistency)而不是Cache一致性(Cache Coherence?)
- HTML获取触发事件的元素id
- Erlang gen_tcp相关问题汇编索引
- 16年软件杯 & 字符串读入处理 & 结构体指针初始化 & 随机函数
- java实现文件下载的几种情况
- goldengate for big data 12.2.0.1.1新增功能
- 英語版Windows Server 2012 R2を日本語化する手順
- 【Halcon】Halcon与OpenCV介绍、比较
- Strust+hibernate+strust2的整合方案(1)
- hdoj 2046 骨牌铺方格(递推)
- java.util.concurrent - Java并发工具包
- linux下 putty 的痛苦编译之路