题解 | 手机键盘

#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
    std::map<char,int> jianpan={{'a',1},{'b',1},{'c',1},{'d',2},{'e',2},{'f',2},{'g',3},{'h',3},{'i',3},{'j',4},{'k',4},{'l',4},{'m',5},{'n',5},{'o',5},{'p',6},{'q',6},{'r',6},{'s',6},{'t',7},{'u',7},{'v',7},{'w',8},{'x',8},{'y',8},{'z',8}};
    std:map<char,int> shunxu={{'a',1},{'b',2},{'c',3},{'d',1},{'e',2},{'f',3},{'g',1},{'h',2},{'i',3},{'j',1},{'k',2},{'l',3},{'m',1},{'n',2},{'o',3},{'p',1},{'q',2},{'r',3},{'s',4},{'t',1},{'u',2},{'v',3},{'w',1},{'x',2},{'y',3},{'z',4}};
    string s;
    while(cin>>s){
        int sum=shunxu[s[0]];
        for(int i=1;i<s.length();i++){
            if(jianpan[s[i]]==jianpan[s[i-1]])
                sum=sum+2+shunxu[s[i]];
            else
                sum=sum+shunxu[s[i]];
        }
        cout<<sum<<endl;
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
01-06 15:18
百度 底层软硬件开发 28*16+4 硕士211
贴心的莲雾向光而行:感觉理想更好,百度这家公司没啥未来
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务