当前位置:网站首页>P1765 手机【入门】
P1765 手机【入门】
2022-07-16 02:32:00 【会编程的露娜】
题目描述
一般的手机的键盘是这样的:

要按出英文字母就必须要按数字键多下。例如要按出 x 就得按 9 两下,第一下会出 w,而第二下会把 w 变成 x。0 键按一下会出一个空格。
你的任务是读取若干句只包含英文小写字母和空格的句子,求出要在手机上打出这个句子至少需要按多少下键盘。
输入格式
一行句子,只包含英文小写字母和空格,且不超过 200 个字符。
输出格式
一行一个整数,表示按键盘的总次数。
样例 #1
样例输入 #1
i have a dream
样例输出 #1
23
最最最最最应该注意的就是,最后一个 else if 判断是否为空格的时候,一定一定要把这个写全!!不要直接用 else 判断,因为可能会有 \n 的情况!
如果直接写 else 判断空格,结果就是全WA,太痛心了。
家银们,写代码千万不要懒啊,是哪种情况就按哪种情况写,一定要写的详细,但也不用特别过于详细。
祝大家一直进步!我也进步。
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stdlib.h>
#include<stdio.h>
#include<fstream>
#include<iomanip>
#include<utility>
#include<unordered_map>
using namespace std;
int main(){
int he=0;
string str;
getline(cin,str);//cin输入字符串遇到空格和回车就停止输入了,所以
int n=str.length();//要用getline可以读入空格,遇到回车输入结束
for(int i=0;i<n;++i){
if(str[i]=='a'||str[i]=='d'||str[i]=='g'||str[i]=='j'||
str[i]=='m'||str[i]=='p'||str[i]=='t'||str[i]=='w')
he+=1;
else if(str[i]=='b'||str[i]=='e'||str[i]=='h'||str[i]=='k'||
str[i]=='q'||str[i]=='n'||str[i]=='u'||str[i]=='x')
he+=2;
else if(str[i]=='c'||str[i]=='f'||str[i]=='i'||str[i]=='l'||
str[i]=='o'||str[i]=='r'||str[i]=='v'||str[i]=='y')
he+=3;
else if(str[i]=='s'||str[i]=='z')
he+=4;
else if(str[i]==' ')
he+=1;
}
cout<<he<<endl;
return 0;
}
边栏推荐
猜你喜欢
![[jailhouse article] bao: a lightweight static partitioning hypervisor for modern multi core embedded](/img/0b/c3a6241ae423f4af7fcef55fb5ab2f.png)
[jailhouse article] bao: a lightweight static partitioning hypervisor for modern multi core embedded

Web programming interview question (2022)

0714下午1,review,

网安学习-权限提升
![[wechat applet] simple and easy-to-use icon (94/100)](/img/2b/11ca1196531fe837ba42142491e896.png)
[wechat applet] simple and easy-to-use icon (94/100)

Redis_ Linux Installation

Rebuild binary tree

Terraform命令行工具介绍、安装、使用

Tri des deux champs dans redis
![[jailhouse article] bao: a modern lightweight embedded hypervisor (2020)](/img/d6/ff217b1690a6fc6c935dcf5e24e926.png)
[jailhouse article] bao: a modern lightweight embedded hypervisor (2020)
随机推荐
0x22, 0x2e services of UDS
HDU word count
Mockito中模拟静态方法
这20道Redis经典面试题你还不会,面试官看都不看你一眼
022. Detailed explanation of static and final keywords
Detailed explanation of assembly language programming skills (with examples)
AcWing 395. 冗余路径 题解(无向图的双连通分量)
Interview frequency: how does MySQL ensure high availability?
2022 Chengdu / Hangzhou / Xiamen / Wuhan product manager certification enrollment brochure (NPDP)
AcWing 395. Redundant path problem solution (biconnected component of undirected graph)
容器健康检查解析
Ftxui basic notes (Hello World)
HDOJ-2057(A + B Again)
[wechat applet] basic horizontal and vertical scroll view (95/100)
技术分享| 快对讲-5G对讲
谷歌 | 图神经网络预训练帮助了分子表征吗
[wechat applet] simple and easy-to-use icon (94/100)
Gson parsing and generating JSON data tool class
Flink basic record supplement
逆向学习笔记(一)