acm.hunnu.edu.cn-10040

Word Reversal 
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB 
Total submit users: 31, Accepted users: 31 
Problem 10040 : No special judgement 
Problem description
  Given a list of words, print the words reversed on separate lines. Each word consists of English letters only.


Input
  The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of a single line, each line contains a word.


Output
  For each test case, print the word reversed on one line.


Sample Input
2
HelloWorld
Madam

Sample Output
dlroWolleH
madaM



package cn.edu.hunnu.acm;

import java.util.Scanner;

public class Acm10040 {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int t = 0;
		t = Integer.parseInt(cin.nextLine());
		char[] word = null;
		char[] reverseWord = null;
		String lines = new String();
		for(int i=0; i<t; i++){
			lines = cin.nextLine();
			word = reverseWord  = new char[lines.length()];
			
			word= lines.toCharArray();
			int k=0;
			for(int j=lines.length()-1; j>=0; j--){
				reverseWord[k] = word[j];
				k++;
			}			
			System.out.println(reverseWord);
		}
		
		
	}
	
}

你可能感兴趣的:(J#)