首页 > 其他 > 详细

UVA 488 - Triangle Wave 水~

时间:2014-04-08 09:03:59      阅读:426      评论:0      收藏:0      [点我收藏+]

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=429

题目大意:

给你振幅A和频率F,让你画出波形。

如:

3
2

波形为:

1
22
333
22
1


1
22
333
22
1

思路:

水。。。直接输出即可。。。。。

要注意的是每两个波形之间有空行。。最后一个没有。

有人问我怎么时间快一点。。。我一开始300+MS,输出字符后就70MS左右的样子。还有一个代码多次提交OJ上显示运行时间会不同。

至于人家怎么0MS过的。我就不知道了。

其实没必要太纠结时间。


bubuko.com,布布扣


#include<cstdio>
const char temp[]={‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘};
void print(int a)
{
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=i;j++)
			printf("%c",temp[i]);
		printf("\n");
	}
	for(int i=a-1;i>=1;i--)
	{
		for(int j=1;j<=i;j++)
			printf("%c",temp[i]);
		printf("\n");
	}
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int a,f;
		scanf("%d%d",&a,&f);
		for(int i=0;i<f;i++)
		{
			print(a);
			if(i!=f-1)
				printf("\n");
		}
		if(T) 
			printf("\n");
	}
	return 0;
}


UVA 488 - Triangle Wave 水~,布布扣,bubuko.com

UVA 488 - Triangle Wave 水~

原文:http://blog.csdn.net/murmured/article/details/23158915

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!