HDOJ/HDU 1321 Reverse Text(倒序输出~)

Problem Description

In most languages, text is written from left to right. However, there are other languages where text is read and written from right to left. As a first step towards a program that automatically translates from a left-to-right language into a right-to-left language and back, you are to write a program that changes the direction of a given text.

Input

The input contains several test cases. The first line contains an integer specifying the number of test cases. Each test case consists of a single line of text which contains at most 70 characters. However, the newline character at the end of each line is not considered to be part of the line.

Output

For each test case, print a line containing the characters of the input line in reverse order.

Sample Input

3

Frankly, I don’t think we’ll make much

money out of this scheme.

madam I’m adam

Sample Output

hcum ekam ll’ew kniht t’nod I ,ylknarF

.emehcs siht fo tuo yenom

mada m’I madam

就是输入一行字符串,然后倒序输出就可以了~

import java.util.Scanner;

/**
 * @author 陈浩翔
 * 2016-5-25
 */
public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t =sc.nextInt();
        sc.nextLine();//读取数字后的回车
        while(t-->0){
            String str =sc.nextLine();
            for(int i=str.length()-1;i>=0;i--){
                System.out.print(str.charAt(i));
            }
            System.out.println();
        }
    }
}
时间: 2024-12-29 09:56:27

HDOJ/HDU 1321 Reverse Text(倒序输出~)的相关文章

HDOJ/HDU 1062 Text Reverse(字符串翻转~)

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 inpu

C#字符串的倒序输出

介绍 在本文中,我将演示如何将字符串的单词倒序输出.在这里我不是要将“John” 这样的字符串倒序为成“nhoJ”,.这是不一样的,因为它完全倒序了整个字符串.而以下代码将教你如何将“你 好 我是 缇娜”倒序输出为“缇娜 是 我 好 你”.所以,字符串的最后一个词成了第一个词,而第一个词成了最后一个词.当然你也可以说,以下代码是从最后一个到第一个段落字符串的读取. 对此我使用了两种方法.第一种方法仅仅采用拆分功能.根据空格拆分字符串,然后将拆分结果存放在一个string类型的数组里面,将数组倒序

Java基础知识强化08:将字符串倒序输出(包括空格)的几种方法

1.最容易想到的估计就是利用String类的toCharArray(),再倒序输出数组的方法了: 1 package himi.hebao05; 2 3 public class TestDemo02 { 4 public static void main(String[] args) { 5 int i = 0; 6 String text = "hebao I love you!"; 7 String result = " "; 8 char[] charArr

【python】 倒序输出字符串

By Dolphin , 20150730 Title : 编写一个程序,获取用户输入的一条信息,然后将其倒序输出. Code: # Reverse Word # By Dolphin,20150730 # word = input("Please Enter a word :") # creat a jumble word  jumble = "" position = len(word) - 1 while word and position != -1 : j

HDU1321 ZOJ1295 Reverse Text

问题链接:HDU1321 ZOJ1295 Reverse Text.基础训练级的题,用C语言编写. 这个问题是首先输入测试例子数量t,然后输入t行字符串,将每一行逆序输出. 利用堆栈后进先出的原理,逆序处理可以使用堆栈来实现. 程序中,使用了一个自行实现的堆栈,简单地实现逆序功能. 本程序使用getchar()函数处理输入流,除了输入字符压栈外,读入的字符直接输出输出,没有使用多余的缓存. 这个问题类似于HDU1062 Text Reverse. AC通过的C语言程序如下: /* HDU1321

HDOJ/HDU 2140 Michael Scofield's letter(字符转换~)

Problem Description I believe many people are the fans of prison break. How clever Michael is!! In order that the message won't be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the he

字符串的倒序输出

package cn.itsource.homeworkday14; /** *  字符串的倒序输出: * 把字符串翻转过来输出 原字符串“avdkfasjks”输出效果”skjsafkdva”; */ //1.通过创建StringBuffer调用它的reverse()方法字符串倒序输出(比较简洁) public class Seven {public static void main(String[] args) { String str6 = "abcdefgh";    Stri

TJU Problem 1644 Reverse Text

注意: int N; cin >> N; cin.ignore(); 同于 int N; scanf("%d\n",&N); 另:关于 cin 与 scanf: scanf是格式化输入,printf是格式化输出. cin是输入流,cout是输出流.效率稍低,但书写简便. 格式化输出效率比较高,但是写代码麻烦. 流输出操作效率稍低,但书写简便. cout之所以效率低,正如一楼所说,是先把要输出的东西存入缓冲区,再输出,导致效率降低. 缓冲区比较抽象,举个例子吧: 曾经

Java实现字符串倒序输出的几种方法

1. 最容易想到的估计就是利用String类的toCharArray(),再倒序输出数组的方法了. import javax.swing.JOptionPane; public class ReverseString { public static void main (String args[]){ String originalString; String resultString = ""; originalString = JOptionPane.showInputDialog