当前位置:网站首页>Mobile keyboard (day 73)
Mobile keyboard (day 73)
2022-07-24 03:02:00 【Zhangxueheng】
List of articles
1: subject
Please calculate according to the mobile phone keyboard (9 Key input method ) How to enter letters , Type the given string ( Consisting of lowercase letters ) The time it takes .
The specific typing rules and time spent are described below :
For characters on the same key , for example a,b,c All in “1” On key , Input a Just press once , Input c You need to press it three times in a row .
If two consecutive characters are not on the same key , You can press , Such as :ad Need to press twice ,kz Need to press 6 Next .
If two consecutive characters are on the same key , You need to wait a while between the two buttons , Such as ac, I pressed a after , It will take a while to press c.
Now suppose it takes a period of time to press each time , The waiting time takes two time periods .
Input format
Input contains multiple sets of test data .
Each group of data occupies one row , Contains a string of lowercase letters .
Output format
For each group of input , One line of output indicates the time it takes to type a given string .
Data range
Each input contains at most 100 Group test data .
All strings are no longer than 100.
sample input :
bob
www
sample output :
7
7
difficulty : Simple
when / Empty limit :1s / 64MB
Total number of passes :943
Total attempts :1398
source : Tsinghua University postgraduate entrance examination machine test questions
Algorithm tags
2: Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int number[] = {
2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5,
6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9
};
int main()
{
string str;
while (cin >> str)
{
int res = 0, last = -1;
for (auto c: str)
{
int t = c - 'a';
for (int i = t; i >= 0; i -- )
if (number[i] == number[t])
res ++ ;
else
break;
if (number[t] == number[last]) res += 2;
last = t;
}
cout << res << endl;
}
return 0;
}
边栏推荐
- [brother hero July training] day 23: dictionary tree
- Symbol类型
- Unity message push
- Unity 消息推送
- (6) Decorator extension [email protected] Principle of use
- Make life full of happiness
- summernote支持自定义视频上传功能
- Leetcode stack and queue questions
- O3DE 的Lumberyard 游戏引擎
- Wonderful! The description of meituan Octo distributed service management system is too clear
猜你喜欢

【HDLBits 刷题】Verilog Language(2)Vectors 部分

Recorded on July 21, 2022

攻防世界WEB练习区(view_source、get_post、robots)

String.split()最详细源码解读及注意事项

Basic knowledge of trigger (Part 2)

Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1

Detailed vector

Summernote rich text editor

The process of solving a bug at work

Hcip --- BGP comprehensive experiment
随机推荐
PMP first-hand data and information acquisition
SSM的技术论坛含前后台
7月开发过程中遇到的问题总结
Jparepository extension interface
summernote富文本编辑器
Why use the well architected framework?
FTP服务与配置
The function of SIP account - tell you what is SIP line
在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架
老公,我们现在无家可归了
AcWing 4499. 画圆 (相似三角形)
go strconv
Summernote font displays Chinese
Cloud native explanation [expansion]
Doodle icons - a free commercial graffiti style icon library, cute, light and unique
Acwing 4499. draw a circle (similar to a triangle)
Ugui source code analysis - maskutilities
Uie: unified model of information extraction
Attack and defense world web practice area (backup, cookie, disabled_button)
Composition API (in setup) watch usage details