Problem Description
时维九月,序属三秋,辽军大举进攻MCA山,战场上两军正交锋.辽军统帅是名噪一时的耶律-James,而MCA方则是派出了传统武将中草药123.双方经过协商,约定在十一月八日正午十分进行射箭对攻战.中草药123早早就开始准备,但是他是武将而不是铁匠,造弓箭的活就交给聪明能干的你了,现在告诉你每种弓箭规格,即箭身的长度,以及每种规格弓箭所需要的数目,要求你把需要的弓箭都输出.
弓箭的基本样子为 “>+—+>”,其中”+—+”为箭身,数据保证箭身长度 > 2

Input
首先输入一个t,表示有t组数据,跟着t行:
每行一个N (N < 50 ),接下去有N行,第i行两个整数Ai , Bi,分别代表需要箭身长度为Ai的弓箭Bi枝. (Ai < 30 , Bi < 10 )
输入数据保证每一个Ai都是不同的.

Output
按照箭身的长度从小到大的顺序依次输出所有需要的弓箭,”每一种”弓箭后输出一个空行.

Sample Input
1
4
3 4
4 5
5 6
6 7

Sample Output

>+-+>
>+-+>
>+-+>
>+-+>

>+--+>
>+--+>
>+--+>
>+--+>
>+--+>

>+---+>
>+---+>
>+---+>
>+---+>
>+---+>
>+---+>

>+----+>
>+----+>
>+----+>
>+----+>
>+----+>
>+----+>
>+----+>

水题一个,注意排序和每种弓箭输出空格就好了~~

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t =sc.nextInt();
        while(t-->0){
            int n =sc.nextInt();
            P2550_2 p[] = new P2550_2[n];
            for(int i=0;i<n;i++){
                p[i] = new P2550_2();
                p[i].a=sc.nextInt();
                p[i].b=sc.nextInt();
            }
            Arrays.sort(p, new Comparator<P2550_2>() {

                @Override
                public int compare(P2550_2 o1, P2550_2 o2) {
                    return o1.a-o2.a;//按照a的大小,从小到大排序
                }
            });
//          for(int i=0;i<n;i++){
//              System.out.println(p[i].a+","+p[i].b);
//          }

            for(int i=0;i<n;i++){//n组
                for(int j=0;j<p[i].b;j++){//每个弓箭有b枝
                    System.out.print(">+");
                    for(int k=0;k<p[i].a-2;k++){
                        System.out.print("-");
                    }
                    System.out.println("+>");
                }
                System.out.println();
            }
        }
    }
}

class P2550_2{
    public int a;
    public int b;
}
posted on 2016-05-17 13:39  cnxo  阅读(154)  评论(0编辑  收藏  举报