HDU 2550 百步穿杨

  • 题目:百步穿杨
  • 题目分析:按照长度排序,然后打印就行,水题
  • 完整代码
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
    int len;
    int num;
}arrow;
int main(void)
{
    arrow a[1000], temp;
    int t, n, i, j, k;
    while (scanf("%d", &t) != EOF)
    {
        while (t-- > 0)
        {
            scanf("%d", &n);
            for (i = 0; i < n; i++)
                scanf("%d%d", &a[i].len, &a[i].num);
            for (i = 0; i < n; i++)
            {
                for (j = 0; j < n - 1; j++)
                {
                    if (a[j].len > a[j + 1].len)
                    {
                        temp = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = temp;
                    }
                }
            }
            for (i = 0; i < n; i++)
            {
                for (k = 0; k < a[i].num; k++)
                {
                    printf(">+");
                    for (j = 0; j < a[i].len - 2; j++)
                        printf("-");
                    printf("+>
");
                }
                printf("
");
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/FlyerBird/p/9052569.html