标签:
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:2543
解决:1401
一个长度不大于100的字符串,其中只有手机按键上有的小写字母
bob www
7 7
模拟题,把手机键盘一打开,然后按着题目意思直接模拟就好。
//Asimple #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <cctype> #include <cstdlib> #include <stack> #include <cmath> #include <set> #include <map> #include <string> #include <queue> #include <limits.h> #define INF 0x7fffffff using namespace std; const int maxn = 105; typedef long long ll; char str[maxn]; int num[] = {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 cnt[] = {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}; bool isOne(char a, char b) { int t1 = num[a-‘a‘]; int t2 = num[b-‘a‘]; if(t1 == t2) { return true; } return false; } int main(){ while(scanf("%s",str) != EOF) { int len = strlen(str); int wait = cnt[(str[0] - ‘a‘)]; for(int i = 1; i < len; i++) { if(isOne(str[i-1], str[i])) { wait = wait + 2; } wait = wait + cnt[(str[i] - ‘a‘)]; } printf("%d\n",wait); } return 0; }
标签:
原文地址:http://www.cnblogs.com/Asimple/p/5939015.html