HDU 2575 Count Problem (水题)

Problem Description
In this problem,we need to count the number that accord with the following rule(include the input number n).Read a integer number n(1<=n<=2^31 - 1) first,then do as following ways:
(1)Do nothing, then exit the process.
(2)Add a digit to the left of it,but the digit should not bigger than the half of the original first digit.For example,from 36 to 136 is legal,but 36 to 236 is illegal because 2 is bigger than half of 3.
(3)After add the digit,continue the process,until could not add digit anymore.


Input
The first line of the input contains an integer T which means the number of test cases.Then T lines follow, each line starts with a number n(1<=n<=2^31 - 1).


Output
For each test case, you should output one line contains the number that accord with the rule start from n.


Sample Input

2
1
6



Sample Output

1
6

Hint

The first case 1 cannot any digital to the leftmost, so the number so only 1.

The second case 6 can add 1, 2, 3 to the leftmost so 16,26,36 are legal. And then 26, 36 also can add 1 to the leftmost so get 126, 136. So 6,16,26,36,126,136 are all legal.The result is 6.


题意:给定一个数n,从n的左边开始添加整数,要求添加的整数满足不大于n的最高位(first digit)的一半,直到不能添加为止;

比如  n=6,满足条件的有6、16、26、36、126、136共6种情况;

  n=10;只有10一种情况,因为10的最高位为1,

故只需要穷举n从1~9共9种情况,


以下AC代码:

#include<stdio.h>   
int main()  
   {  
       int t,n,a[10]={0,1,2,2,4,4,6,6,10,10};  
       scanf("%d",&t);  
       while(t--)  
       {  
           scanf("%d",&n);  
           while(n>9)
             n/=10;  
           printf("%d\n",a[n]);  
       }  
       return 0;  
   }  


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值