题目:
描述
The numberic keypad on your mobile phone looks like below:
123
456
789
0
suppose you are holding your mobile phone with single hand. Your thumb points at digit 1. Each time you can 1)press the digit your thumb pointing at.2)moveyour thumb right,3)move your thumb down. Moving your thumb left or up is not allowed.
By using the numeric keypad under above constrains, you can produce some numbers like 177 or 480 while producing other numbers like 590 or 52 is impossible.
Given a number K, find out the maximum number less than or equal to K that can be produced.
输入描述:
the first line contains an integer T, the number of testcases.
Each testcase occupies a single line with an integer K.
For 50%of the data ,1<=K<=999.
For 100% of the data, 1<=K<=10^500,t<=20.
输出描述:
for each testcase output one line, the maximum number less than or equal to the corresponding K that can be produced.
翻译:
你的手机上的数字键盘如下所示:123 456 789 0 假设你是用单手拿着你的手机。你的拇指指向第1位手指。每次都可以按数字 你的拇指指着你。将拇指向右移动,将拇指向下移动。不允许将拇指向左或向上移动。通过使用上述约束下的数字小键盘,您可以生成一些数字,比如 177或480,而产生其他数字,如590或52,是不可能的。给定一个数字K,找出可以产生的小于或等于K的最大数目。
第一行包含一个整数T,即测试用例的数量。每个测试箱占用包含整数K的一行。对于50%的数据,使用1<=K<=999。对于100%的数据,1<=K<=10^500,t<=20。
对于每个测试例输出一行,可以产生的小于或等于相应K的最大数字。