当前位置:网站首页>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;
}
边栏推荐
- Unity 消息推送
- Composition API (in setup) watch usage details
- Summary of problems encountered in the development process in July
- 攻防世界WEB练习区(webshell、command_execution、simple_js)
- In the future, when the interviewer asks why you don't recommend using select *, please answer him loudly!
- How to get gait energy map Gei
- 198. House raiding
- O3DE 的Lumberyard 游戏引擎
- Summernote supports custom video upload function
- Relational expression greater than > less than < congruence = = = Nan isnan() logical operator double sense exclamation point!! & |% +-- Short circuit calculation assignment expression shortcut operat
猜你喜欢

自定义kindeditor富文本默认的宽高

Wonderful! The description of meituan Octo distributed service management system is too clear

Ugui source code analysis - maskutilities

SIGIR‘22 推荐系统论文之多样性篇

在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架

Lcd1602——斌哥51

The new idea 2022.2 was officially released, and the new features are nice

Skywalking distributed system application performance monitoring tool - upper

An introductory example of structure and combinatorial ideas in go language

String.split() the most detailed source code interpretation and precautions
随机推荐
uva11389
summernote支持自定义视频上传功能
[AMC] federal quantification
Description of relevant resolutions in video on demand
Unscramble the category and application principle of robot vision
String.split()最详细源码解读及注意事项
日常杂谈(一)
Interpretation of steam education with the deepening of educational reform
MariaDB related instructions
Summernote supports custom video upload function
Soft test --- fundamentals of programming language (Part 1)
Symbol type
SSM's technical forum includes front and back offices
Unity message push
在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架
Uie: unified model of information extraction
Summary of problems encountered in the development process in July
Lumberyard game engine of o3de
Is it safe for qiniu to open an account? Is the Commission of 30000 reliable?
JVM初始