题解 | #手机键盘#

手机键盘

https://www.nowcoder.com/practice/20082c12f1ec43b29cd27c805cd476cd

#include <iostream>
#include<vector>
using namespace std;

int main() {
    vector<int> first_character={0,3,6,9,12,15,19,22};
    string str;
    while (cin >> str) { // 注意 while 处理多个 case
        int res=0,pre=-1,last;
        for(int i=0;i<str.size();i++){
            int index=1,c=str[i]-'a';
            while(index<first_character.size()&&first_character[index]<=c) index++;
            last=index-1;
            if(last==pre)
                res+=2;
            res+=c-first_character[last]+1;
            pre=last;
        }
        cout<<res<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

07-18 14:34
门头沟学院 Java
感觉招聘要求好高,这都是招什么人才
电气电子小朋友:你都说了这是大疆,无人机顶级企业,薪资30k-50k,要求高是正常的
点赞 评论 收藏
分享
Vincent777...:实习经历可以考虑放上去,对于软件使用方面可以细化一些,比如调整为:熟悉基于LSDYNA的瞬态动力学仿真分析,熟悉基于WORKBENCH的结构拓扑优化
我的简历长这样
点赞 评论 收藏
分享
07-03 16:13
嘉应学院 Python
xiaolihuam...:很明显骗子,如果是hr直接约你面试了,哪用得着内推,如果是员工的话,你得多优秀,一线员工直接加你微信,
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务