递减打印最大的N位数到1
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 21 Accepted Submission(s) : 4
Times New Roman | Verdana | Georgia
← →
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
吴迎
Statistic | Submit | Back
闲来无聊做的其它学校出的题、、
这道题让我做的筋疲力尽啊。。由于在航电上面找不到题目,就不写题号了
#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;
}