HDOJ2550

http://acm.hdu.edu.cn/showproblem.php?pid=2550

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
  
  
>+-+> >+-+> >+-+> >+-+> >+--+> >+--+> >+--+> >+--+> >+--+> >+---+> >+---+> >+---+> >+---+> >+---+> >+---+> >+----+> >+----+> >+----+> >+----+> >+----+> >+----+> >+----+>

代码1:

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

struct D{
	int x;
	int y;
};

D a[32];

bool operator < (const D& l,const D&s){
	return l.x<s.x;
}

int main(){
	int t,i;
	cin>>t;
	while(t--){
		int n,count=0,flag=0;
		cin>>n;
		for(i=0;i<n;i++){
			cin>>a[i].x>>a[i].y;
		}
		sort(a,a+n);
		for(i=0;i<n;i++){
			while(a[i].y--)
				cout<<">+"<<string(a[i].x-2,'-')<<"+>"<<endl;
			cout<<endl;
		}
	}
	return 0;
}

代码2:

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct arrow
{
	int len,num;
}s[50];
struct cmp
{
	bool operator()(arrow a,arrow b)
	{
		return a.len>b.len;
	}
};
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		priority_queue<arrow,vector<arrow>,cmp>a;
		int i,j,n;
		cin>>n;
		for(i=1;i<=n;i++)
		{
			cin>>s[i].len>>s[i].num;
			a.push(s[i]);
		}
		for(i=1;i<=n;i++)
		{
			
			int t1=a.top().num,t2=a.top().len;
			a.pop();
			while(t1--)
			{
				cout<<">+";
				for(j=1;j<=t2-2;j++)
					cout<<"-";
				cout<<"+>"<<endl;
			}
			cout<<endl;
		}	
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值