24h購物| | PChome| 登入
2012-05-13 10:51:35| 人氣939| 回應0 | 上一篇 | 下一篇

[UVA] 11530 - SMS Typing

推薦 0 收藏 0 轉貼0 訂閱站台

B

SMS Typing

Input: Standard Input

Output: Standard Output

 

 

Cell phones have become an essential part of modern life. In addition to making voice calls, cell phones can be used to send text messages, which are known as SMS for short. Unlike computer keyboards, most cell phones have limited number of keys. To accommodate all alphabets, letters are compacted into single key. Therefore, to type certain characters, a key must be repeatedly pressed until that character is shown on the display panel.

 

In this problem we are interested in finding out the number of times keys on a cell phone must be pressed to type a particular message.

 

In this problem we will assume that the key pad of our cell phone is arranged as follows.

---------------------

|      | abc | def  |

---------------------

| ghi  | jkl | mno  |

---------------------

| pqrs | tuv | wxyz |

---------------------

|      | <SP>|      |

---------------------

In the above grid each cell represents one key. Here SP means a space. In order to type  the letter ‘a’,  we must press that key once, however to type ‘b’ the same key must be repeatedly pressed twice and for ‘c’ three times. In the same manner, one key press for ‘d’, two for ‘e’ and three for ‘f’.  This is also applicable for the remaining keys and letters. Note that it takes a single press to type a space.

 

Input

The first line of input will be a positive integer T where T denotes the number of test cases. T lines will then follow each containing only spaces and lower case letters. Each line will contain at least 1 and at most 100 characters.

 

Output

For every case of input there will be one line of output. It will first contain the case number followed by the number of key presses required to type the message of that case. Look at the sample output for exact formatting.

 

Sample Input                            Output for Sample Input

2

welcome to ulab

good luck and have fun

Case #1: 29

Case #2: 41

 




#include <stdio.h>

int main() {
    int t, Case = 0;
    int s[] = {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};
    char str[1000];
    scanf("%d", &t);
    getchar();
    while(t--) {
        gets(str);
        int ans = 0, i;
        for(i = 0; str[i]; i++) {
            if(str[i] == ' ')
                ans++;
            else
                ans += s[str[i]-'a'];
        }
        printf("Case #%d: %d\n", ++Case, ans);
    }
    return 0;
}

台長: Morris
人氣(939) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][二分圖最大匹配] 10080 - Gopher II
此分類上一篇:[UVA][Math] 1264 - Binary Search Tree

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文