HDU 2575 Count Problem (水题)

来源:互联网 发布:windows ad域搭建 编辑:程序博客网 时间:2024/05/16 09:25
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 0
原创粉丝点击