sicily 1010. 单词数值

本题主要是Hash思想的应用

 

课程上机练习题

Contest ends in 8 months 27 days
 
Xieyz3ss12330344
You havn't any signature yet.
Logout
 
     
 
 
1010. 单词数值
 
 
Total: 2514 Accepted: 526
 
     
     
 
Time Limit: 1sec    Memory Limit:256MB
Description

小明喜欢发短信一天他突然想出一种定义短信中单词的值的方法也许能够揭示某种规律。

小明的手机键盘如下图所示

 

输入法为字母输入即每次输入一个字母例如需要输入字母x由于x在数字键9排在第二位因此需要按下9键两次

小明定义单词的值如下单词中每个字母不区分大小写的值等于按键数值按键次数单词的值等于所有字母的值之和如单词word的值为9+6*3+7*3+3=51

Input

第一行给出单词数T1<=T<=100,000)。

接下来T每行一个单词单词最大长度不超过100

Output

输出T每行为单词的对应值

Sample Input
 Copy sample input to clipboard
3
Word
I
Day
Sample Output
51
12
32

Problem Source: 课程上机练习题

 
   

代码:

 1 // Problem#: 8657
 2 // Submission#: 2493101
 3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
 4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
 5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University
 6 #include<iostream>
 7 #include<map>
 8 #include<stdio.h>
 9 #include<string.h>
10 using namespace std;
11 int main() {
12     char alp[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
13     'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w','x',
14     'y', 'z'};
15     int num[26] = {2, 4, 6, 3,6, 9, 4, 8, 12, 5, 10, 15, 6, 12, 18,
16     7, 14, 21, 28, 8, 16, 24, 9, 18, 27, 36};
17     map<char, int> keyboard;
18     for (int i = 0; i < 26; i++) {
19         keyboard[alp[i]] = num[i];
20     }
21     int words;
22     int sum = 0;
23     char *word;
24     word = new char[101];
25     scanf("%d", &words);
26     for (int i = 0; i < words; i++) {
27         scanf("%s", word);
28         int len = strlen(word);
29         for (int j = 0; j < len; j++) {
30             if ( 'A' <= word[j] && word[j] <= 'Z')
31                  word[j] = word[j] + 32;
32             sum += keyboard[word[j]];
33         }
34         printf("%d\n", sum);
35         sum = 0;
36    }
37    return 0;
38 }                                 

 

posted @ 2013-12-04 01:03  XYZ篮球  阅读(448)  评论(0编辑  收藏  举报