算法
打表
嗯开两个数组, 一个存点击时间, 另一个存字母所在区域(一共8个区域)
C++ 代码
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int click_time[26] = {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}; // 点击需要的时间
int position[26] = {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8}; // 一共8个区域
int main()
{
string s;
while (cin >> s)
{
int res = click_time[s[0] - 'a'];
for (int i = 1; i < s.size(); i ++ )
{
if (position[s[i] - 'a'] == position[s[i - 1] - 'a']) res += 2; // 如果落在同一区域, 那么就要等2个时间段
res += click_time[s[i] - 'a']; // 加一个按键时间
}
printf("%d\n", res);
}
return 0;
}