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)使 ...
随机推荐
- 垃圾回收(GC Garbage collection)
JS有自动垃圾清理机制, 如果有不需要用的对象,只需要设置对象=null即可 Var a = new object() a = null
- Java第2次作业
我认为这一次的作业还是比较好的,对自己的学习有很大帮助.
- 关于layui中tablle 渲染数据后 sort排序问题
最近在使用easyweb框架做后台管理,案例可见https://gitee.com/whvse/EasyWeb. 其中遇到了 sort排序问题, html代码:<table class=&quo ...
- sublime text 3 ,React,html元素自动补全方法(用Emmet写法写jsx中的html)
1. 安装emmet: Preferences -> Package Control -> Install Package -> emmet 2. 配置emmet: Preferen ...
- JAVA第九次作业
JAVA第九次作业 (一)学习总结 1.用思维导图对javaIO操作的学习内容进行总结. 参考资料: XMind. 2.下面的程序实现了文件的拷贝,但采用的是一个字节一个字节的读写方式,效率很低.使用 ...
- Shell脚本中的逻辑判断、文件目录属性判断、if的特殊用法、case判断
1.Shell脚本中的逻辑判断 格式1:if 条件 ; then 语句; fi格式2:if 条件; then 语句; else 语句; fi格式3:if …; then … ;elif …; then ...
- install MariaDB 10.2 on Ubuntu 18
Here are the commands to run to install MariaDB 10.2 from the MariaDB repository on your Ubuntu syst ...
- myBatis---接口代理开发(demo)
一.概述 使用接口代理开发,可以不用写接口的实现类,而采用的是MapperFactoryBean代理的实现类. * 接口代理方式开发,遵循四大原则 * 1.方法名 == mapper.xml的id名 ...
- 必做作业3:原型化设计:地铁扫码app
一.设计背景 伴随着地铁规模的快速扩张,使用手机扫码进出站成为了一种新型的地铁出行方式.在今天的北京和上海,地铁扫码已经极为普遍,广州和深圳也正在快速普及这种新方式.相信在不久的将来,其他拥有地铁或者 ...
- 打印杨辉三角—Python
b=[] for i in range(0,9): c=[] for j in range(0,i): if j==0: c.append(b[i-1][j]) if j<=i-2:#执行完第一 ...