题目描述
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.

IDEA

1.首先确定从一个数字digit1能否到达另一个数字digit2,能够到达需要满足:digit2(x2,y2)在digit1(x1,y1)的右下方,即x1<=x2,y1<=y2

2.输入的数从左到右检查两个相邻的数字能否到达,i->i+1位

如果能够到达,则继续检查下一位

如果不能达到,i+1的数字减一,再检查能否到达...

若果i+1减到负数,则第i位数字减一,并回溯一位,将i指向前一位(i--),将后几位都置为9

在进行检查

CODE

#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
void locate(int digit,int &x,int &y){digit=digit?--digit:10;x=digit/3;y=digit%3;
}
int reach(int digit1,int digit2){int x1,y1;int x2,y2;locate(digit1-'0',x1,y1);locate(digit2-'0',x2,y2);return x1<=x2&&y1<=y2;
}
int main(){#ifndef ONLINE_JUDGEfreopen("input.txt","r",stdin);#endif int n;cin>>n;while(n--){string str;cin>>str;for(int i=0;i<str.size()-1;i++){while(!reach(str[i],str[i+1])){str[i+1]--;if(str[i+1]<0){str[i]--;i--;}for(int j=i+2;j<str.length();j++){str[j]='9';}}}cout<<str<<endl;} return 0;
} 

Numeric Keypad相关推荐

  1. 【每天一道算法题】Numeric Keypad

    题目描述 The numberic keypad on your mobile phone looks like below: 123 456 789  0  suppose you are hold ...

  2. C#,电话数字键盘问题(Mobile Numeric Keypad problem)的算法与源代码

    提供移动数字键盘.您只能按向上.向左.向右或向下至当前按钮的按钮.不允许您按最下面一行的角点按钮(即.*和#). 移动键盘 给定一个数N,找出给定长度的可能数. 示例: 对于N=1,可能的数字数为10 ...

  3. S3C6410 KeyPad驱动(上)

    ********************************LoongEmbedded******************************** 作者:LoongEmbedded(kandi ...

  4. 【Unity3D】 KeyCode 键码

    Key codes returned by Event.keyCode. These map directly to a physical key on the keyboard. KeyCode是由 ...

  5. linux pycharm 数字键盘失效

    linux下 pycharm 社区版,2020.01.02版本 pycharm中数字键失效,小键盘是键盘锁关闭时的状态,且按Num键无法解除 2. 键盘上方数字键为符号键,按不按shift都是输入符号 ...

  6. 键盘各个键对应的ASCLL值

    // 摘要:         //     The bitmask to extract modifiers from a key value.         Modifiers = -65536, ...

  7. linux 键盘 数值,键盘数值对照表

    键盘数值对照表 按键 数值 描述 DOM_VK_CANCEL 3 Cancel key DOM_VK_HELP 6 Help key DOM_VK_BACK_SPACE 8 退格键 DOM_VK_TA ...

  8. word 替换 增加引号_如何在Word 2013文档中替换部分(不是全部)智能引号

    word 替换 增加引号 Word includes a setting that allows you to automatically convert straight quotes to sma ...

  9. Android 4 学习(20):ActionBar

    参考<Pro Android 4.0> ActionBar 11.0之后,ActionBar在Activity中默认存在,可以在代码中设置其显示与否: ActionBar actionBa ...

最新文章

  1. Win7 任务栏影藏、显示速度提升
  2. android x86怎么引导,Android、Ubuntu、win三系统引导求教
  3. c语言程序中的基本功能,c语言程序中的基本功能模块为什么?
  4. 数学,原来可以这么美!
  5. VAE(变分自编码器)学习笔记
  6. MATLAB学习笔记(八)
  7. 【Vegas原创】imp/exp导入导出数据
  8. 实习生有年终奖吗_“辞职,一定要赶在发年终奖前!”为什么我建议你一定要年前跳槽...
  9. adb shell dumpsys activity top
  10. java iplimage 头文件_javaCV图像处理之Frame、Mat和IplImage三者相互转换(使用openCV进行Mat和IplImage转换)......
  11. mysql 左连接写法_mysql左连接复杂正确写法
  12. mt6735 [AT Command] AP下发AT+CLAC命令后 ,手机出现宕机
  13. 虚拟麦克风音频输入_硅麦克风电路连接指南
  14. python自学难吗?零基础学python难吗?
  15. ubuntu18.4 安装谷歌浏览器
  16. Linux系统使用userdel命令删除用户
  17. Groovy 百度云分享下载各个版本SDK
  18. 网络爬虫实战之从妹子图开始
  19. 通过docker安装FastDFS
  20. 共识算法Raft概论

热门文章

  1. 基于破壳漏洞的蠕虫实践
  2. Focusing Attention Network(FAN)自然图像文本识别 学习笔记
  3. 我在京东做研发第五期:京东云自研服务器,如何将开发成本降低 60% 的同时还更低碳环保?
  4. Glide最详细走读!看不懂我自杀!
  5. [转载]AutoIT3 vs AutoHotkey
  6. 最新HAL库SDMMC初始化SD报HardFault
  7. 汇聚数据库创新力量 GBASE携手openGauss助企业数字化转型
  8. 高并发与大流量解决方案
  9. matlab怎么发声,听听函数,看看声音--Matlab的sound()函数
  10. Python+Flask框架搭建可视化网站