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. python 中的 try/except/else/finally语句

    1.python中try/except/else/finally正常的语句是这样的: try: normal excute block except A: Except A handle except ...

  2. linux 内核升级

    LINUX 内核升级 linux 内核官网 https://www.kernel.org/ POST BIOS(boot sequence) 所选择的启动设备次序的MBR中是否有引导程序, ----& ...

  3. Ubuntu下安装Koala

    1.下载koala ,官方网址 目前官方链接的到百度云上的包好像有问题,不能安装,这里分享下 https://yunpan.cn/ckAF4L3TR4kKG (提取码:179a) 2.执行 $ sud ...

  4. Meta标签用法大全

    meta是html文档在head标签里定义的一个对文档进行描述的功能性标签 meta标签有下面的作用: 1.搜索引擎优化(SEO) 2.定义页面使用语言 3.自动刷新并指向新的页面 4.实现网页转换时 ...

  5. Ios二维码扫描(系统自带的二维码扫描)

    Ios二维码扫描 这里给大家介绍的时如何使用系统自带的二维码扫描方法和一些简单的动画! 操作步骤: 1).首先你需要搭建UI界面如图:下图我用了俩个imageview和一个label 2).你需要在你 ...

  6. TCP/IP协议学习(七) 基于C# Socket的Web服务器---动态通讯实现

    目录 (1).基于Ajax的前端实现 (2).Web服务器后端处理 一个完整的web服务器,不仅需要满足用户端对于图片.文档等资源的需求:还能够对于用户端的动态请求,返回指定程序生成的数据.支持动态请 ...

  7. springMVC下jsp引用外部js,css等静态资源的解决方法

    直入主题. 1. web.xml对springMVC配置如下: <servlet> <description>Spring MVC配置</description> ...

  8. Python_Day9_Socket编程

    本节内容: Socket语法及相关 SocketServer实现多并发 socket概念 socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道来实现数据的互相传递. 我们 ...

  9. AxureRP8实战手册(基础31-40)

    AxureRP8实战手册(基础31-40) 本文目录 基础31.     切换元件库 第2章          页面设置 基础32.     设置页面居中 基础33.     设置页面背景(图片/颜色 ...

  10. Table 'performance_schema.session_variables' doesn't exist

    出现标题所示错误时设置如下参数可以解决!set @@global.show_compatibility_56=ON;