本题主要是Hash思想的应用
课程上机练习题
Contest ends in 8 months 27 days
aaarticlea/gif;base64,R0lGODlhEAAQANUAAIi1AO75zrPiH7zdVpnMALXXTbXgM63NTf///9XnnL/kTcTzM/n97qbcAMjkcdX3cbXwALrmM/X65snzS7jbTaviAKPZAL7sM7zgTcrocf//78XsTfb94a3lAL/qOsbzOp/TAMHtPMv1TLXmMdDvcfD8zsHkVsLpTf///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUUACgALAAAAAAQABAAAAaKQBRgSCwWhY+kUklqZjLDx2JKpV4iBkeUKuIgEJzJNbuder/gawQzFFEZaATjamEDRJA8HM3oNBp2eHlnXxwVfxRDE3kQH3EefyCJABsdjCWFhyCSQycVnyF7DB4WIAQFQwoNAgFxXxIDp0MYJq6uCQdDFF8Mvb6/uQAFBRTFxcPDB8oAQkbOQyhBADs=" alt="Xieyz3" />ss12330344
You havn't any signature yet.
1010. 单词数值
|
||||||
|
||||||
Time Limit: 1sec Memory Limit:256MB
Description
小明喜欢发短信,一天他突然想出一种定义短信中单词的值的方法,也许能够揭示某种规律。 小明的手机键盘如下图所示: 输入法为字母输入,即每次输入一个字母,例如需要输入字母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 Sample Output
51 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 ;
}