当前位置:网站首页>One question per day,

One question per day,

2022-06-25 14:50:00 䨁 逦

Title Description

The keyboard of a mobile phone is like this :

You have to press the number key many times to press the English letters . For example, to press  x  Just press 9 both parties , The first one will come out  w, And the second one will  w  become  x.0 Press the key once and a space will appear .

Your task is to read several sentences that contain only lowercase letters and spaces , Find out at least how many keystrokes you need to press to type this sentence on your mobile phone .

Input format

A line of sentences , Contains only lowercase letters and spaces , And no more than 200 Characters .

Output format

One line, one integer , Indicates the total number of keystrokes .

I/o sample

Input #1 Copy

i have a dream

Output #1 Copy

23

code

 

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char c[205];

int main(){
    int all=0,n=0;
    while((c[n]=getchar())!=EOF)
    {
        n++;
    }
    for(int i=0;i<n;i++)
    {
        if(c[i]==' ') all++;
        else 
        if('a'<=c[i]&&c[i]<='r')
        {
            int a=0; 
            a= c[i]-'a'+1;
            
            if(a%3==0)
            all+=3;
            else 
            all=a%3+all;
            printf("%d\n",all);
        }
        else
        if(c[i]=='p'||c[i]=='t'||c[i]=='w')
        all++;
        else 
        if(c[i]=='q'||c[i]=='u'||c[i]=='x')
        all+=2;
        else 
        if(c[i]=='r'||c[i]=='v'||c[i]=='y')
        all+=3;
        else 
        if(c[i]=='s'||c[i]=='z')
        all+=4;
        
    }
    printf("%d",all);
    return 0;

原网站

版权声明
本文为[䨁 逦]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200518464750.html