码迷,mamicode.com
首页 > 编程语言 > 详细

递减打印最大的N位数到1 (2015年 JXNU_ACS 算法组暑假第一次周赛)

时间:2015-08-09 18:54:07      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:递减打印最大的n位数到1

递减打印最大的N位数到1

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 21   Accepted Submission(s) : 4

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem Description

给定一个数字N,M,递减打印最大的N位数到1的前M个数,例如给定2 5,则打印99 98 97 96 95。

Input

输入包含多组测试样例。
对于每个测试案例,输入一个数字n,m(n<=10^3,1<=m<=min((10^n)-1,10^3))。

Output

对应每个测试案例,依次打印从最大的N位数到1的前m位。

Sample Input

1 9

Sample Output

9
8
7
6
5
4
3
2
1

Author

吴迎


闲来无聊做的其它学校出的题、、

这道题让我做的筋疲力尽啊。。由于在航电上面找不到题目,就不写题号了

#include <stdio.h>
#include <math.h>
int main()
{
	int n,m,temp,x;
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		int flag=0;
 		if(m<10)
		temp=1;
		else if(m<100)
		temp=2;
		else if(m<1000)
		temp=3;
		else if(m<10000)
		temp=4;
		int t=1;
		while(m--)
		{
			for(int i=0;i<n-temp;i++)
			printf("9");
			x=pow(10,temp)-t;
			if((n-temp))
			{
				for(int i=1;i<temp-(int)log10(x);i++)
				printf("0");
			}
			printf("%d\n",x);
			t++;
		}
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

递减打印最大的N位数到1 (2015年 JXNU_ACS 算法组暑假第一次周赛)

标签:递减打印最大的n位数到1

原文地址:http://blog.csdn.net/su20145104009/article/details/47377891

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!