Title Link: http://ac.jobdu.com/problem.php?pid=1079
Detailed Links: https://github.com/zpfbuaa/JobduInCPlusPlus
Reference code:
////1079 Mobile keyboard. cpp//Jobdu////Created by Pengfei_zheng on 03/05/2017.//copyright©2017 Pengfei_zheng. All rights reserved.//#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<cstring>#include<cmath>#include<climits>#defineMax_size 110using namespacestd;CharStr[max_size];intpos[ -]={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};intkase[ -]={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}; intMain () { while(SCANF ("%s", str)! =EOF) { intLen = (int) strlen (str); intsum = kase[str[0]-'a']; for(inti =1; i < Len; i++){ if(pos[str[i]-'a']!=pos[str[i-1]-'a']) {sum+ = (kase[str[i]-'a']); } Else{sum+=2+kase[str[i]-'a']; }} printf ("%d\n", sum); } return 0;}/************************************************************** problem:1079 User:zpfbuaa language:c++ Re sult:accepted time:10 Ms memory:1520 kb****************************************************************/
Topic 1079: Phone keypad (correspondence relationship)