19 degrees per day topic 1079: Mobile keypad

Source: Internet
Author: User

time limit:1 seconds

Memory limit:32 MB

Special question: No

submitted:2543

Resolution:1401

Title Description:
according to the phone keypad input letters, the calculation of the time spent, such as: A,b,c are in the "1" key, input a only need to press, input C need to press three consecutive times. If the two consecutive characters are not on the same key, you can press directly, such as: ad needs to press two, KZ needs to press 6 if the two consecutive characters on the same key, then two keys between the need to wait a period of time, such as AC, after pressing A, you need to wait a while to press C. It now assumes that a time period is required for each hit, and that the wait time takes two time periods. Now given a string of characters, you need to figure out how much time it takes.
Input:

A string of a length not greater than 100, where only the lowercase letters on the phone keys

Output:
The
input may include multiple sets of data, and for each set of data, the time required for the output to be pressed out by the input string
Sample input:
Bobwww
Sample output:
77

Simulation problem, the phone keyboard opened, and then the title of the direct simulation is good.

//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>#defineINF 0x7fffffffusing namespacestd;Const intMAXN = the; typedefLong Longll;CharSTR[MAXN];intNum[] = {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};intCnt[] = {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};BOOLIsone (CharACharb) {intT1 = num[a-'a']; intT2 = num[b-'a']; if(T1 = =T2) {        return true; }    return false;}intMain () { while(SCANF ("%s", str)! =EOF) {        intLen =strlen (str); intwait = cnt[(str[0] -'a')];  for(inti =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;}

19 degrees per day topic 1079: Mobile keypad

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.