天天看點

深夜切題——Keyboard of a Mobile Telephone

Keyboard of a Mobile Telephone 時間限制:500MS  記憶體限制:1000K

Description

 Now almost every student has a mobile telephone. But do you have making attention to the keyboard of a mobile telephone? This is the keyboard of a normal mobile telephone:

深夜切題——Keyboard of a Mobile Telephone

It will show different letters if you press one key different times, for example you press the key “2” once it will show a letter ‘a’, twice show a ‘b’. And notice that press the key ‘0’ once will show a space. Now give you a sentence, which contains only lowercases and space, calculate how much times to press the keyboard at least to show the sentence. 

輸入格式

 The first line contains an integer n, which means the number of cases. Per case consist of only one sentence, which contains only lowercases and spaces and its length less or equal 200.

輸出格式

 Per case output an integer, which is the least times to press the keyboard, in one line.

輸入樣例

1

this problem is so easy

輸出樣例

 53 

來源

 By Hanqiu 

恰好學了一種叫map(映射)的東西。于是乎暴力之。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;
int main() {
    map<char,int> Iphone;
    Iphone['a']=Iphone['d']=Iphone['g']=Iphone['j']=Iphone['m']=Iphone['p']=Iphone['t']=Iphone['w']=Iphone[' ']=1;
    Iphone['b']=Iphone['e']=Iphone['h']=Iphone['k']=Iphone['n']=Iphone['q']=Iphone['u']=Iphone['x']=2;
    Iphone['c']=Iphone['f']=Iphone['i']=Iphone['l']=Iphone['o']=Iphone['r']=Iphone['v']=Iphone['y']=3;
    Iphone['s']=Iphone['z']=4;
    int T;
    char s[205];
    scanf("%d",&T);
    getchar();
    while(T--){
        gets(s);
        int l=strlen(s),c=0;
        for(int i=0;i<l;++i)
            c+=Iphone[s[i]];
        printf("%d\n",c);
    }
    return 0;
}
           

就是手打的有點累- -

CTRL+C