[技术| 编程·课件·Linux] ACM趣题天天练 3 Reverse Text

yel_hb · 发布于 2012-08-22 19:33 · 1247 次阅读
86
本帖最后由 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
源自:http://acm.zju.edu.cn/ 1295题

...顶上,继续水题...天天练两天别就断了...

评分

参与人数 3学分 +12 收起 理由
紫凝雪儿 + 6 节奏带的好
service + 3 原创帖子,对同学们很有帮助!
admin + 3 感谢您为软院筒子们提供有用信息!

查看全部评分

共收到 9 条回复
fghhslk · #2 · 2012-8-22 20:40:05  回复 支持 反对
已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();

	}
}


评分

参与人数 2学分 +11 收起 理由
紫凝雪儿 + 6 哇靠,java 厉害啊
service + 5 赞一个!程序很工整无问题!

查看全部评分

yel_hb · #3 · 2012-8-22 20:43:20  回复 支持 反对
本帖最后由 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]

点评

帖子再编辑下吧,好多   详情 回复 发表于 2012-8-22 20:44
帖子再编辑下吧,好多   详情 回复 发表于 2012-8-22 20:44
fghhslk · #4 · 2012-8-22 20:44:52  回复 支持 反对
yel_hb 发表于 2012-8-22 20:43
自己接一个...
[mw_shl_code=cpp,true]#include
#include

帖子再编辑下吧,好多&nbsp;
fghhslk · #5 · 2012-8-22 20:44:53  回复 支持 反对
yel_hb 发表于 2012-8-22 20:43
自己接一个...
[mw_shl_code=cpp,true]#include
#include

帖子再编辑下吧,好多&nbsp;

点评

发错格式了...成了JavaScript  详情 回复 发表于 2012-8-22 20:45
yel_hb · #6 · 2012-8-22 20:45:58  回复 支持 反对
fghhslk 发表于 2012-8-22 20:44
帖子再编辑下吧,好多&nbsp;

发错格式了...成了JavaScript

点评

难怪。。。刚才差点看瞎眼了  详情 回复 发表于 2012-8-22 20:54
难怪。。。刚才差点看瞎眼了  详情 回复 发表于 2012-8-22 20:53
fghhslk · #7 · 2012-8-22 20:53:59  回复 支持 反对
yel_hb 发表于 2012-8-22 20:45
发错格式了...成了JavaScript

难怪。。。刚才差点看瞎眼了
fghhslk · #8 · 2012-8-22 20:54:01  回复 支持 反对
yel_hb 发表于 2012-8-22 20:45
发错格式了...成了JavaScript

难怪。。。刚才差点看瞎眼了
qingyanglxy · #9 · 2012-8-22 21:21:37  回复 支持 反对
顶版主~                    
justcx · #10 · 2012-8-22 22:31:55  回复 支持 反对
[C++] 纯文本查看 复制代码
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
      string s;
      char c[75];
      int n;
      cin>>n;
      n++;
      while(n--)
    {
        cin.getline(c,75);
        s=c;
        reverse(s.begin(),s.end());
        cout<<s<<endl; 
    }
    return 0;
}
回帖
B Color Image Link Quote Code Smilies
Command + Enter
快速回复 返回顶部 返回列表