ACM趣题天天练 3 Reverse Text
本帖最后由 simon3322 于 2012-8-22 21:15 编辑Reverse Text
Time Limit: 2 Seconds Memory Limit: 65536 KBIn 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 SpecificationThe 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 SpecificationFor each test case, print a line containing the characters of the input line in reverse order.
Sample Input3
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题
...顶上,继续水题...天天练两天别就断了...
已AC。
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 编辑
自己接一个...
#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;
}
cout << endl;
}
}
return 0;
}
yel_hb 发表于 2012-8-22 20:43 static/image/common/back.gif
自己接一个...
#include
#include
帖子再编辑下吧,好多 yel_hb 发表于 2012-8-22 20:43 static/image/common/back.gif
自己接一个...
#include
#include
帖子再编辑下吧,好多 fghhslk 发表于 2012-8-22 20:44 static/image/common/back.gif
帖子再编辑下吧,好多
发错格式了...成了JavaScript yel_hb 发表于 2012-8-22 20:45 static/image/common/back.gif
发错格式了...成了JavaScript
难怪。。。刚才差点看瞎眼了 yel_hb 发表于 2012-8-22 20:45 static/image/common/back.gif
发错格式了...成了JavaScript
难怪。。。刚才差点看瞎眼了 顶版主~
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s;
char c;
int n;
cin>>n;
n++;
while(n--)
{
cin.getline(c,75);
s=c;
reverse(s.begin(),s.end());
cout<<s<<endl;
}
return 0;
}
页:
[1]