acm.hunnu.edu.cn-10040

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


}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值