本帖最后由 simon3322 于 2012-8-22 21:15 编辑 Reverse Text Time Limit: 2 Seconds Memory Limit: 65536 KB 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 Specification 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 Specification 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 ...顶上,继续水题...天天练两天别就断了... |
[技术| 编程·课件·Linux] ACM趣题天天练 3 Reverse Text
yel_hb
· 发布于 2012-08-22 19:33
· 1247 次阅读
转载文章时务必注明原作者及原始链接,并注明「发表于 软院网 RuanYuan.Net 」,并不得对作品进行修改。
已AC。 [Java] 纯文本查看 复制代码 import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { List<StringBuffer> strBfrs = new ArrayList<StringBuffer>(); Scanner sc = new Scanner(System.in); int n; n = Integer.parseInt(sc.nextLine()); while (n-- > 0) strBfrs.add(new StringBuffer(sc.nextLine())); for (StringBuffer strBfr : strBfrs) { for (int i = 0, j = strBfr.length()-1; i < j; i++, j--) { char temp = strBfr.charAt(i); strBfr.setCharAt(i, strBfr.charAt(j)); strBfr.setCharAt(j, temp); } System.out.println(strBfr); } sc.close(); } } |
评分
本帖最后由 yel_hb 于 2012-8-22 20:45 编辑 自己接一个... [C++] 纯文本查看 复制代码 #include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { string str; int i,n; while(cin >> n) { getchar(); while(n--) { getline(cin,str); i = str.length(); while(--i > -1) { cout << str[i]; } cout << endl; } } return 0; } [i] |
顶版主~ |