noip2010-Universal group Semi-finals simulation test-first question-Mobile phone

Source: Internet
Author: User

Topic Background Background

Now the use of mobile phones more and more widely Title Description DescriptionThe general phone's keyboard is like this:
To press the English letter, you have to press the number key more. For example, to press X to press 92, the first will be a W,
And the second will turn W into X. 0 Click to make a space.
Your task is to read a few sentences containing only small letters and spaces in English, and find out what to say on the phone.
At least how many times the child needs to press the keyboard. input/output format input/output Input Format:
A single sentence, containing only English lowercase letters and spaces, and no more than 200 characters. output Format:
An integer line that represents the total number of times that the keyboard was pressed. input and Output sample sample Input/output sample Test point # #

Input Sample:

I have a dream

Sample output:

23

Idea: This problem is relatively simple, you can first hit the table, this is relatively fast (record each button to press the number of times), enter only one character at a time, find the answer in the table plus counter can.

Note: input data has a number of sentences, one line, so you need to read in the file.

The code is as follows:

1#include <stdio.h>2#include <string.h>3 intans1[ -]={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,1};//make a table to count the number of times each key is required4 intPhoneChara[])5 {6     intans=0, I;7      for(i=0; I<strlen (a); i++)  8     {9         if(a[i]!=' ')//LettersTen         { Oneans+=ans1[a[i]- the];//the counter plus the numbers in the table A         } -         Else     //space, counter + + -         { theans+=1; -         } -     }     -     returnans; + } - intMain () + {      A     Chara[201];  at gets (a); -      while(A[strlen (a)-1]!=eof)//If the end of the file is not reached, the incoming function -     { -printf"%d\n", Phone (a)); - gets (a); -     }             in     return 0; -}

noip2010-Universal group Semi-finals simulation test-first question-Mobile phone

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.