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
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);
}
}
}
本文介绍了一个简单的算法问题——单词反转。任务要求对于输入的一系列英文单词,程序需要输出每个单词的反转形式。文章提供了一个Java实现示例,通过读取多组测试数据,并对每组数据中的单词进行反转处理。
447

被折叠的 条评论
为什么被折叠?



