sicily 1010. 单词数值

本题主要是Hash思想的应用

 
     
 
 
1010. 单词数值
 
 
Total: 2514 Accepted: 526
 
     
     
 
Time Limit: 1sec    Memory Limit:256MB
Description

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

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

sicily 1010. 单词数值

sicily 1010. 单词数值

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

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

Input

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

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

Output

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

Sample Input
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard
3
Word
I
Day
Sample Output
51
12
32

Problem Source: 课程上机练习题

 
   

代码:

 // Problem#: 8657
// Submission#: 2493101
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<map>
#include<stdio.h>
#include<string.h>
using namespace std;
int main() {
char alp[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w','x',
'y', 'z'};
int num[] = {, , , ,, , , , , , , , , , ,
, , , , , , , , , , };
map<char, int> keyboard;
for (int i = ; i < ; i++) {
keyboard[alp[i]] = num[i];
}
int words;
int sum = ;
char *word;
word = new char[];
scanf("%d", &words);
for (int i = ; i < words; i++) {
scanf("%s", word);
int len = strlen(word);
for (int j = ; j < len; j++) {
if ( 'A' <= word[j] && word[j] <= 'Z')
word[j] = word[j] + ;
sum += keyboard[word[j]];
}
printf("%d\n", sum);
sum = ;
}
return ;
}
上一篇:关于checkbox的checked属性和change事件


下一篇:HDU - 6311 Cover(无向图的最少路径边覆盖 欧拉路径)