P13419 [COCI 2012/2013 #6] BAKA
简单模拟题,根据题意模拟即可。可以发现,在拨到 A、B 和 C 时,所需要的时间为 秒;拨到 D、E 和 F 时,所需要的时间为 秒。可以发现,拨到每个字母需要的时间是这个字母对应的数字 ,所以可以用一个数组表示其每个下标对应的字母所需要的时间,遍历字符串累加即可。
#include <bits/stdc++.h>
using namespace std;
int need[] = {3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10};
int ans;
int main() {
string s;
cin >> s;
for (char c : s) {
ans += need[c - 'A'];
}
cout << ans << endl;
return 0;
}