标签:
一个长度不大于100的字符串,其中只有手机按键上有的小写字母
bob www
7 7
这破题要做出来还得去看看手机键盘,那不知道手机键盘的布置怎么办?
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 5 char str[102]; 6 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}; 7 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}; 8 9 bool isOne(char a, char b) { 10 int t1 = num[a-‘a‘]; 11 int t2 = num[b-‘a‘]; 12 if(t1 == t2) { 13 return true; 14 } 15 return false; 16 } 17 18 int main(int argc, char const *argv[]) 19 { 20 while(scanf("%s",str) != EOF) { 21 int len = strlen(str); 22 int wait = cnt[(str[0] - ‘a‘)]; 23 24 for(int i = 1; i < len; i++) { 25 if(isOne(str[i-1], str[i])) { 26 wait = wait + 2; 27 } 28 wait = wait + cnt[(str[i] - ‘a‘)]; 29 } 30 printf("%d\n",wait); 31 } 32 return 0; 33 }
标签:
原文地址:http://www.cnblogs.com/jasonJie/p/5819810.html