Quicksum
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16488   Accepted: 11453

Description

A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data.

For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces.

A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets "ACM" and "MID CENTRAL":

        ACM: 1*1  + 2*3 + 3*13 = 46

MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650

Input

The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.

Output

For each packet, output its Quicksum on a separate line in the output.

Sample Input

ACM
MID CENTRAL
REGIONAL PROGRAMMING CONTEST
ACN
A C M
ABC
BBC
#

Sample Output

46
650
4690
49
75
14
15

Source

 
原题大意: 一种类似于字符哈希的东西,输入然后输出就好了。
解题思路:简单模拟。

#include<stdio.h>
#include<string.h>
int chash(char *p,int len)
{
int i,sum=0;
for(i=1;i<=len;++i) if(*p!=' ') sum+=i*(int)((*p++)-'A'+1); else ++p;
return sum;
}
int main()
{
char s[300];
while(gets(s)&&s[0]!='#') printf("%d\n",chash(s,strlen(s)));
return 0;
}

  

[字符哈希] POJ 3094 Quicksum的更多相关文章

  1. POJ 3094 Quicksum 难度:0

    http://poj.org/problem?id=3094 #include<iostream> #include <string> using namespace std; ...

  2. poj 3094 Quicksum

    #include <stdio.h> #include <string.h> ]; int main() { ; int i,len; while(gets(word)) { ...

  3. POJ 3094 Quicksum(简单的问题)

    [简要题意]:题意是非常easy. 看样能理解 [分析]:略. 读取字符串. // 200K 0Ms #include<iostream> using namespace std; int ...

  4. HDU3973 线段树 + 字符哈希

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3973 , 线段树 + 字符哈希,好题. 又学了一种新的哈希方法,hhhh~ 解法: 想法是用P进制的数 ...

  5. 哈希—— POJ 3349 Snowflake Snow Snowflakes

    相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions ...

  6. 剑指 Offer 50. 第一个只出现一次的字符 + 哈希表 + 有序哈希表

    剑指 Offer 50. 第一个只出现一次的字符 Offer_50 题目详情 方法一:使用无序哈希表 package com.walegarrett.offer; /** * @Author Wale ...

  7. 哈希 poj 3349

    n个雪花 判断有没有相同的 正的和倒的相同都可以 哈希一下  比的少了就可以 #include<stdio.h> #include<algorithm> #include< ...

  8. 剑指offer-面试题50-第一个只出现一次的字符-哈希表

    /* 题目: 求字符串第一个只出现一次的字符. */ /* 思路: 使用map遍历两次,第一次计数,第二次找到计数为1的第一个字符. */ #include<iostream> #incl ...

  9. 哈希 poj 2002

    n个点 求其中有几个正方形 n<1000 暴力4个点就不行了 大概2个点还可以 根基(x*x+y*y)%素数 hash 一下 告诉你2个点求 另外2个点 画个图推一下 重复要/2; #inclu ...

随机推荐

  1. 对json数据的遍历

    json格式变化多样,可嵌套好几层,这里只记录了一些遍历方法,具体数据格式具体分析~ "data1": { "key1": [ {"name" ...

  2. git无法定位程序输入点libiconv

    使用git clone时,报以下错误: 解决方案: 将git\bin\下的libiconv-2.dll复制到\git\libexec\git-core\下即可

  3. 关于GDB使用

    编译时要加上 -g  才可以提供给gdb符号信息. 启动: $gdb (target-program) 单步执行: $n 设断点: 1.程序入口 $break (functionname()) 2.行 ...

  4. JavaScript 中的对象

    JavaScript 中的对象 在 JavaScript 中,对象是数据(变量),拥有属性和方法. JavaScript 中的所有事物都是对象:字符串.数字.数组.日期,等等.   访问对象的属性 访 ...

  5. EasyUI、Struts2、Hibernate、spring 框架整合

    经历了四个月的学习,中间过程曲折离奇,好在坚持下来了,也到了最后框架的整合中间过程也只有自己能体会了. 接下来开始说一下整合中的问题和技巧: 1,  jar包导入 c3p0(2个).jdbc(1个). ...

  6. c# base和this关键字总结

    base:用于在派生类中实现对基类公有或者受保护成员的访问,但是只局限在构造函数.实例方法和实例属性访问器中.MSDN中小结的具体功能包括:    (1)调用基类上已被其他方法重写的方法.     ( ...

  7. ucos中的三种临界区管理机制

    熟悉ucos,或者读过Jean.J.Labrosse写过的ucos书籍的人,一定会知道ucos中著名的临界区管理宏:OS_ENTER_CRITICAL()和OS_EXIT_CRITICAL(). 同样 ...

  8. hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)

    hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...

  9. window.onload和window.onscroll

    之前我的一个页面里写了引入了2个js,一个是包含置顶的侧面客服,一个是定位导航.2个开始都用了window.onload,发现第一个js的定位导航没有显示,被第2个js覆盖了,当我去掉第2个js的wi ...

  10. jQuery.eq() 函数

    eq() 函数 获取当前对象中指定索引所对应的的元素 语法 $selector.eq(index)//index为指定索引,值为数字型 返回值 返回值为一个对象 实例说明 代码 <!DOCTYP ...