This article for Bo Master original key, reproduced when please inform Bo Master, and the original link in the text eye-catching position.
Title Link: https://www.luogu.org/problem/show?pid=1765
Title Description
The general phone's keyboard is like this:
1 2 ABC 3 def
4 Ghi 5 JKL 6 MnO
7 PQRS 8 TUV 9 WXYZ
* 0 #
To press the English letter, you have to press the number key more. For example, to press the X to press 92, the first will be a W, and the second will turn W into X. 0 Click to make a space.
Your task is to read a few sentences that contain only English lowercase letters and spaces, and find out how much you need to press the keyboard at least to hit the sentence on your phone.
Input/output formatInput Format:
A single sentence, containing only English lowercase letters and spaces, and no more than 200 characters.
output Format:
An integer line that represents the total number of times that the keyboard was pressed.
Input/Output sampleInput Sample # #:
I have a dream
Sample # # of output:
23
Description
_noi Guide Issue 2010 popularity (10)
Analysis:
The problem is very water ... Just read into the time with Cin.getline (), never used before.
Cin.getline (string name, maximum possible length, terminator);
Where the Terminator is not specifically specified, the default is ' \ n ', which is the newline character. This allows you to freely read the spaces, or implement other read-in requirements.
AC Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 6 using namespacestd;7 8InlinevoidReadint&x)9 {Tenx =0;Charch = GetChar (), C =ch; One while(Ch <'0'|| CH >'9') c = ch, ch =GetChar (); A while(Ch <='9'&& CH >='0') x = (x<<1) + (x<<3) +ch-'0', ch =GetChar (); - if(c = ='-') x =-x; - } the - intcnt[ -] = {1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4}; - //correct use of arrays (errors) - Charline[1005]; + - intMain () + { A intAns =0; atCin.getline (Line, +,'\ n'); - intLen =strlen (line); - for(inti =0; I < len;++i) - { - if(Line[i] >='a'&& Line[i] <='Z') -Ans + = cnt[line[i]-'a']; in Else if(Line[i] = =' ') -Ans + =1; to } +printf"%d\n", ans); - return 0; the}
Rokua P1765 Mobile Phone _noi Guide Issue 2010 popularization (10)