Nine degree OJ 1079 phone keypad (analog)

Source: Internet
Author: User

Topic 1079: Mobile keypad

time limit:1 seconds

Memory limit:32 MB

Special question: No

submitted:1989

Resolution:1069

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

Last hand keyboard diagram

My idea is: to map each letter to the corresponding key, on each key according to the order and distinguish, m[' a ']=10,m[' B ']=11,m[' C ']=12,m[' d ']=20 ...

So the value of the hash table as long as 10 bits is the same, it means that on a key, digit number plus one is to press the number of times

#include <stdio.h> #include <string.h>int ans;char s[120];char m[256];void init () {memset (m,0,sizeof (m));    m[' A ']=m[' B ']=m[' C ']=10;    m[' B ']+=1;    m[' C ']+=2;    m[' d ']=m[' e ']=m[' f ']=20;    m[' E ']+=1;    m[' F ']+=2;    m[' g ']=m[' h ']=m[' I ']=30;    m[' h ']+=1;    m[' i ']+=2;    m[' J ']=m[' K ']=m[' l ']=40;    m[' K ']+=1;    m[' L ']+=2;    m[' m ']=m[' n ']=m[' o ']=50;    m[' n ']+=1;    m[' O ']+=2;    m[' P ']=m[' Q ']=m[' R ']=m[' s ']=60;    m[' Q ']+=1;    m[' R ']+=2;    m[' s ']+=3;    m[' t ']=m[' u ']=m[' V ']=70;    m[' u ']+=1;    m[' V ']+=2;    m[' W ']=m[' x ']=m[' y ']=m[' z ']=80;    m[' x ']+=1;    m[' y ']+=2; M[' z ']+=3;}    int main (int argc, char *argv[]) {//Freopen ("1079.in", "R", stdin);    Init ();        while (~SCANF ("%s", s)) {ans=0;            for (int i=0;i<strlen (s); ++i) {if (i==0) {ans+= (m[s[i]]%10+1);                } else if (M[S[I]]/10==M[S[I-1]]/10) {ans+=2;            ans+= (m[s[i]]%10+1);  } else {              ans+= (m[s[i]]%10+1);    }} printf ("%d\n", ans); } return 0;} /************************************************************** problem:1079 User:kirchhoff language:c Resu lt:accepted time:10 Ms memory:912 kb****************************************************************/




Nine degree OJ 1079 phone keypad (analog)

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.