当前位置:网站首页>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;
}
边栏推荐
- SkyWalking分布式系统应用程序性能监控工具-上
- The process of solving a bug at work
- [brother hero July training] day 23: dictionary tree
- Go IO operation - file write
- String.split() the most detailed source code interpretation and precautions
- The solution of using non root user management in secure stand-alone database under general machine environment
- c语言小练习
- Openresty Lua resty balancer dynamic load balancing
- Rules for generating 13 digit barcode EAN-13 Code: the thirteenth digit is the verification code obtained by calculating the first twelve digits.
- uva11389
猜你喜欢

PMP first-hand data and information acquisition

CMT registration - Google Scholar ID, semantic scholar ID, and DBLP ID

Nirvana rebirth! Byte Daniel recommends a large distributed manual, and the Phoenix architecture makes you become a God in fire

攻防世界WEB練習區(view_source、get_post、robots)

The simple use of ADB command combined with monkey is super detailed

Diversity of SIGIR '22 recommendation system papers

summernote富文本编辑器

Lumberyard game engine of o3de

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

攻防世界WEB练习区(webshell、command_execution、simple_js)
随机推荐
FTP服务与配置
攻防世界WEB练习区(backup、cookie、disabled_button)
[management / upgrade] * 02. View the upgrade path * FortiGate firewall
TCP connection principle
Ugui source code analysis - Mask
Attack and defense world web practice area (view_source, get_post, robots)
JVM初始
Example of producer consumer code implemented by the destructor framework without lock
Custom log annotation, request fetching
软考---程序设计语言基础(上)
kettle
SSM family financial management personal financial management system accounting system
CMT registration - Google Scholar ID, semantic scholar ID, and DBLP ID
Interpretation of steam education with the deepening of educational reform
Relational expression greater than > less than < congruence = = = Nan isnan() logical operator double sense exclamation point!! & |% +-- Short circuit calculation assignment expression shortcut operat
Do securities companies really have principal guaranteed financial products?
AcWing 4499. 画圆 (相似三角形)
【英雄哥七月集训】第 23天: 字典树
X Actual combat - Cloud Server
Unity Message push