POJ3094 Quicksum
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 18517   Accepted: 12712

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

 
题目分析:
 
     计算只含[大写字母+空格]的字符串的校验和.
     其中每个字母有其对应的特征值,空格=0,A=1,B=2,...,Z=26
     校验和 = 所有 [字符的位置(从1开始) * 字母特征值] 之和
 
#include <memory.h>
#include <iostream>
using namespace std; // 被校验字符串的最大长度
const static int MAX_LEN = ; int getFeatureVal(char c); int main(void) {
char str[MAX_LEN] = { '\0' };
while(true) {
gets(str); // 输入字符串中包含空格,不能用cin接收
int len = strlen(str);
if(strlen(str) <= || str[] == '#') {
break;
} int quicksum = ;
for(int i = ; i < len; i++) {
quicksum += ((i + ) * getFeatureVal(str[i]));
}
cout << quicksum << endl; memset(str, '\0', sizeof(char) * len);
}
return ;
} int getFeatureVal(char c) {
return (c == ' ' ? : (c - 'A' + ));
}

POJ3094 Quicksum的更多相关文章

  1. [字符哈希] POJ 3094 Quicksum

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

  2. Quicksum -SilverN

    quicksum Given a string of digits, find the minimum number of additions required for the string to e ...

  3. ACM——Quicksum

    Quicksum 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:615            测试通过:256 描述 A chec ...

  4. poj3094

    Quicksum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13523   Accepted: 9407 Descrip ...

  5. Quicksum

    Quicksum Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Subm ...

  6. TJU Problem 2520 Quicksum

    注意: for (int i = 1; i <= aaa.length(); i++) 其中是“ i <= ",注意等号. 原题: 2520.   Quicksum Time L ...

  7. H - Quicksum(1.5.3)

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...

  8. HDU.2734 Quicksum

    Quicksum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  9. POJ3094 Sky Code(莫比乌斯反演)

    POJ3094 Sky Code(莫比乌斯反演) Sky Code 题意 给你\(n\le 10^5\)个数,这些数\(\le 10^5\),问这些这些数组成的互不相同的无序四元组(a,b,c,d)使 ...

随机推荐

  1. 高吞吐低延迟Java应用的垃圾回收优化

    高吞吐低延迟Java应用的垃圾回收优化 高性能应用构成了现代网络的支柱.LinkedIn有许多内部高吞吐量服务来满足每秒数千次的用户请求.要优化用户体验,低延迟地响应这些请求非常重要. 比如说,用户经 ...

  2. python多进程拷贝数据

    from multiprocessing import Pool,Manager import os #完成拷贝文件 def copyFile(filename,oldname,newname,que ...

  3. 微信小程序上传后发布或者体验版测试无数据解决办法

    在做微信小程序开发的过程中,发现小程序在本地调用接口的数据都显示,但是上传之后,发现手机体验没有数据.以下为解决办法: 1.先清除缓存试试. 2.打开微信小程序工具右上角的详情——项目设置,将“不校验 ...

  4. Servlet中的编码问题

    对于response.setContentType()和response.setCharacterEncoding()的理解: 经过一些实践,对着两个方法有了一些自己的理解,有可能今后的学习中会发现自 ...

  5. java——————基础总结2

    一 程序中常见的错误: 1,语法错误 2, 逻辑错误 3,运行时错误 二 定义class类的时候,如果前面加个public 那么class的类名必须要和文件名一致,否则就会 出现编译错误 三 编译源文 ...

  6. 解决long类型传到前端损失精度问题

    原因: 解决办法:https://blog.csdn.net/xiaoxiangzi520/article/details/76522242 经过验证,发现上述解决办法回导致前端先后台传输数据时导致j ...

  7. js 文件异步上传 显示进度条 显示上传速度 预览文件

    通常文件异步提交有几个关键 1.支持拖拽放入文件.2.限制文件格式.3.预览图片文件.4.上传进度,速度等,上传途中取消上传.5.数据与文件同时上传 现在开始笔记: 需要一个最基础的元素<inp ...

  8. ubuntu 主题和zsh终端

    ubuntu 主题和zsh终端 1) sudo apt-get install unity-tweak-tool  sudo add-apt-repository ppa:noobslab/theme ...

  9. WMI tester

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. Nginx failing to load CSS and JS files (MIME type error)

    Nginx failing to load CSS and JS files (MIME type error) Nginx加载静态文件失败的解决方法(MIME type错误) 上线新的页面,需要在n ...