hdu 1062 Text Reverse
2015-06-27 19:58
302 查看
题意:输入一串单词反序的句子,输出单词正序的句子;
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20435 Accepted Submission(s): 7797
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,表示测试事件的个数。
T test cases follow.Each test case contains a single line with several words. There will be at most 1000 characters in a line.
紧接着又T行测试事件。每一个测试事件有一行,且由多个单词组成。字符串的长度不超过1000。
Output
For each test case, you should output the text which is processed.
对于每个测试事件,你应该输出处理后的数据。
Sample Input
Sample Output
Author
Ignatius.L
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); String temp = sc.nextLine();// 接收回车符 while (t-- > 0) { String s = sc.nextLine(); String[] strs = s.split(" "); temp = ""; for (int i = 0; i < strs.length; i++) { for (int j = strs[i].length() - 1; j >= 0; j--) { temp += strs[i].charAt(j); } if ((i + 1) == strs.length) { continue; } temp += " "; } if (s.endsWith(" ")) {// 接收最后一个空格 temp += " "; } System.out.println(temp); } } }
Text Reverse
反向文本Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20435 Accepted Submission(s): 7797
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,表示测试事件的个数。
T test cases follow.Each test case contains a single line with several words. There will be at most 1000 characters in a line.
紧接着又T行测试事件。每一个测试事件有一行,且由多个单词组成。字符串的长度不超过1000。
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. 记住用getchar()去接收回车符,然后用 gets() 去读取字符。
Author
Ignatius.L
相关文章推荐
- java并发电子书合集
- spring+hibernate
- forward 与redirect 区别
- leetcode Word Search回溯算法
- 学习jms(一)——基本实例
- 【Java EE 学习 22 下】【单线程下载】【单线程断点下载】【多线程下载】
- I/O复用epoll
- Android打造带删除的EditText并且实现输入框密码显示、隐藏
- FPGA图像处理系列——直方图均衡
- 2015年毕业生收到的offer和薪资透露
- 虚拟机Linux----Ubuntu1204----安装jdk1.8
- DataTables选择行并删除(删除单行)
- 关于EasyUI Json格式不匹配的问题
- 黑马程序员——Java基础——数组
- Mac系统查看端口占用和杀死进程
- java WebSocket 简易聊天消息推送
- Custom Data Service Providers
- Rectangle Area
- 自定义Data Service Providers
- Java的3种Base64加密方法