Numeric Keypad
来源:互联网 发布:mimo软件 编辑:程序博客网 时间:2024/06/05 23:46
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.
示例1
输入:
3
25
83
131
输出:
25
80
129
#include<iostream>#include<string>#include<vector>using namespace std;vector<string> helper = { "0", "0123456789", "0235689", "369", "0456789", "05689", "69", "0789", "089", "9" };//这里只用一个数int main(){ string num="0"; for (int i = 0; i < num.length(); i++) { while (helper[num[i] - '0'].find(num[i + 1]) == -1) { if (num[i + 1] == '0') { num[i]--; num[i + 1] = '9'; } else { num[i + 1]--; } for (int j = i + 2; j < num.length(); ++j) { num[j] = '9'; } } if (num[i + 1] == '0') { for (int j = i + 1; j < num.length(); ++j) { num[j] = '0'; } } } cout << num << endl;}
- Numeric Keypad
- Numeric Keypad
- Numeric Keypad
- Numeric Keypad
- Numeric Keypad
- Numeric Keypad 解题报告
- hihocoder #1153 : Numeric Keypad
- Numeric Keypad:多思考,别蛮力!
- hihoCoder week 85 Numeric Keypad 【DFS】
- Numeric Keypad 微软2016校园招聘在线笔试第二场
- keypad driver
- keypad driver
- keypad driver
- Optimal Keypad
- keypad 错误
- Android Hard Keypad
- S3C6410 KeyPad驱动(上)
- S3C6410 KeyPad驱动(下)
- 用ul、li做横排导航
- TCP面向连接Socket
- eclipse jetty启动内存溢出
- Unity物体穿墙问题
- 使用CSDN-markdown编辑器
- Numeric Keypad
- CSS清除浮动的五种方式
- 前端笔记
- 机房重构---单例模式应用
- 【Linux基础】Linux的5种IO模型详解
- HDU--1241 简单DFS
- 自定义view之viewpager的使用
- Caffe学习(2):在Ubuntu下运行手写体数字教程
- NumPy的详细教程