yel_hb 发表于 2012-8-22 19:33:30

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题

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

fghhslk 发表于 2012-8-22 20:40:05

已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:43:20

本帖最后由 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;
}

fghhslk 发表于 2012-8-22 20:44:52

yel_hb 发表于 2012-8-22 20:43 static/image/common/back.gif
自己接一个...
#include
#include


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

fghhslk 发表于 2012-8-22 20:44:53

yel_hb 发表于 2012-8-22 20:43 static/image/common/back.gif
自己接一个...
#include
#include


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

yel_hb 发表于 2012-8-22 20:45:58

fghhslk 发表于 2012-8-22 20:44 static/image/common/back.gif
帖子再编辑下吧,好多&nbsp;

发错格式了...成了JavaScript

fghhslk 发表于 2012-8-22 20:53:59

yel_hb 发表于 2012-8-22 20:45 static/image/common/back.gif
发错格式了...成了JavaScript

难怪。。。刚才差点看瞎眼了

fghhslk 发表于 2012-8-22 20:54:01

yel_hb 发表于 2012-8-22 20:45 static/image/common/back.gif
发错格式了...成了JavaScript

难怪。。。刚才差点看瞎眼了

qingyanglxy 发表于 2012-8-22 21:21:37

顶版主~                  

justcx 发表于 2012-8-22 22:31:55

#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]
查看完整版本: ACM趣题天天练 3 Reverse Text