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
#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的更多相关文章
- [字符哈希] POJ 3094 Quicksum
Quicksum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16488 Accepted: 11453 Descri ...
- Quicksum -SilverN
quicksum Given a string of digits, find the minimum number of additions required for the string to e ...
- ACM——Quicksum
Quicksum 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:615 测试通过:256 描述 A chec ...
- poj3094
Quicksum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13523 Accepted: 9407 Descrip ...
- Quicksum
Quicksum Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Subm ...
- TJU Problem 2520 Quicksum
注意: for (int i = 1; i <= aaa.length(); i++) 其中是“ i <= ",注意等号. 原题: 2520. Quicksum Time L ...
- H - Quicksum(1.5.3)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...
- HDU.2734 Quicksum
Quicksum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- POJ3094 Sky Code(莫比乌斯反演)
POJ3094 Sky Code(莫比乌斯反演) Sky Code 题意 给你\(n\le 10^5\)个数,这些数\(\le 10^5\),问这些这些数组成的互不相同的无序四元组(a,b,c,d)使 ...
随机推荐
- 免app下载笔趣阁小说
第一次更新:发现一个问题,就是有时候网页排版有问题的话容易下载到多余章节,如下图所示: 网站抽风多了一个正文一栏,这样的话就会重复下载1603--1703章节. 解决办法: 于是在写入内容前加了一个章 ...
- vue学习之路一:安装vue-element-admin项目
今天看到一个vue网站,觉得很好,立马又有学习vue的冲动了,话不多说,直接贴项目网址: https://github.com/PanJiaChen/vue-element-admin/blob/ma ...
- 搭建opencv javaweb项目
搭建opencv javaweb项目 用到的技术maven.git.ssm.opencv.javaweb 搭建opencv javaweb项目时,踩了很多坑:怀疑过spring,想过python,最后 ...
- npm 遇到的坑
在脚手架方式搭建react项目时,输入命令:npm install -g create-react-app,出现错误: UNABLE_TO_VERIFY_LEAF_SIGNATUREUNABLE_TO ...
- 数据库中无数据时查询数据为空,但出现空指针异常的解决方案(转载https://blueskator.iteye.com/blog/2096026)
异常:java.lang.NullPointerException 解决方案: try{ hotelImageList = ihotelImgManager.query(hiqc); }catch(E ...
- 解题报告 『宝藏(Prim思想 + 访问顺序随机)』
原题地址 本以为不过是一道Prim算法模版题,但貌似只能得45分,虽然对我这种蒟蒻来说已经够了. 然而同机房大佬表示可以用模拟退火A了此题,遂习之,终无所获. 然而机缘巧合之下习得了另一种随机算法,于 ...
- java项目---用java重命名文件(1星)
package Demo; import java.io.File; public class FileRename { public static boolean Rename(String old ...
- xc笔记
2019-03-20正式开始准备 --言语理解与表达------------------------------------------------------- 分为 1.逻辑填空 2.片段阅读 ...
- MySQL数据库使用规范
一.建表规约 1.[强制]表达是与否概念的字段,必须使用is_xxx的方式命名,数据类型是unsigned tinyint (1表示是,0表示否) 说明:任何字段如果为非负数,必须是unsigned ...
- Linux下的常用文本编辑器
Linux的文本编辑器 ed 在早期的unix平台上,ed可以说是唯一的编辑工具.它是一个很古老的行编辑器,vi这些编辑器都是从ed 演化而来.行编辑器使用起来很不方便,每次只能对一行进行操作,.而后 ...