HDU 2550 百步穿杨

#include <cstdio>
#include <algorithm>
using namespace std;
struct arc{
    int a;
    int b;
};

bool cmp(arc x,arc y)
{
    return (x.a<y.a);
}

int main()
{
    int test;
    scanf("%d",&test);
    while (test--)
    {
        int n;
        scanf("%d",&n);
        arc a[10000];
        for (int i=0; i<n; i++)
        scanf("%d%d",&a[i].a,&a[i].b);
        sort(a,a+n,cmp);
        for (int b=0; b<n; b++)
        {
            for(int i=1; i<=a[b].b; i++)
            {
                printf(">+");
                for (int j=3; j<=a[b].a; j++)
                printf("-");
                printf("+>
");
            }
            printf("
");
        }
    }
    return 0;
}            

注意点:在这道题中学会了sort的各种用法,还有结构体的定义,需要注意的是结构体定义完后一定要加上‘;’。

原文地址:https://www.cnblogs.com/forever97/p/3489562.html