本文主要是介绍hdu_2550 百步穿杨,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2550
分析:没有什么好分析的,按题意打印就好了。
代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
int L;
int num;
bool operator < (const Node &a)const
{
return L<a.L;
}
};
bool cmp(Node a,Node b)
{
return a.L<b.L;
}
Node p[55];
void prin(int n)
{
printf(">+");
for(int i=n-2;i>0;i--) printf("-");
printf("+>\n");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i,j;
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d %d",&p[i].L,&p[i].num);
sort(p,p+n);
for(i=0;i<n;i++)
{
for(j=0;j<p[i].num;j++)
{
prin(p[i].L);
}
printf("\n");
}
}
return 0;
}
···蛋疼的是,在比赛的时候prin()函数里写了个n-4-,-.赛后再写的时候,题目也不看清楚直接输出这种类型的箭——<+--+<。有自切小JJ的冲动T_T.
这篇关于hdu_2550 百步穿杨的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!