P13419 [COCI 2012/2013 #6] BAKA
~~(这是一道代码实现十分简单的题目,就不废话,直接干吧!)
更具题目要求,我们只需要把需要拨的字母在拨号盘上对应的数字加上 就可以算出拨这个字母所需要的时间,再将所有字母的所需要时间累加起来就可以算出答案。
话不多说,直接上代码:
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <set>
using namespace std;
int ans = 0;
string s;
int a[30] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6,
6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9}; // 打表计算
int main() {
ios::sync_with_stdio(0), cin.tie(0),
cout.tie(0); // 输入输出加速语句,可以不加。
cin >> s;
for (int i = 0; i < s.size(); i++) {
ans += a[s[i] - 'A'] + 1; // 字母在拨号盘上对应数字加1算出所需要的时间
}
cout << ans << endl; // 输出答案
return 0;
}