您的位置:首页 > 其它

hdu 1062 Text Reverse

2015-06-27 19:58 302 查看
题意:输入一串单词反序的句子,输出单词正序的句子;

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: