题解 | #手机键盘#
手机键盘
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")
