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)使 ...
随机推荐
- sort_gff.py
import sys infile = sys.argv[1]outfile = sys.argv[2] gff_list = []fh = open(infile)for x in fh: i ...
- POJ - 1222: EXTENDED LIGHTS OUT (开关问题-高斯消元)
pro:给定5*6的灯的状态,如果我们按下一个灯的开关,它和周围4个都会改变状态.求一种合法状态,使得终状态全为关闭: sol:模2意义下的高斯消元. 终于自己手打了一个初级板子. #include& ...
- seriviceWorker 小结
serviceWorker 的状态 install → activate. 1.初进页面,此前未加载过serviceWorker,直接进入install状态,随后进入activate状态,但是此时se ...
- JavaScript 查找图中连接两点的所有路径算法
1.把图看成以起点为根节点的树 2.使用深度遍历算法遍历路径 3.遍历到节点为目标节点时,保存这条路径 find2PointsPath(sourceId, targetId) { const { no ...
- 关于使用jQuery操作dom时的一点发现
<body> <ul> <li>list item 1</li> <li>list item 2</li> <li> ...
- C++跨平台集成websocketpp
之前给公司写了一个用于消息交互的服务器,移植到Linux上之后发现H5-Websocket模块经常出问题,而该模块是另一位已经离职同事编写的,所以修改和维护都存在一定的困难,索性就直接把这个模块替换掉 ...
- pymongo中的连接操作:Connection()与MongoClient()
class MongoClient(pymongo.common.BaseObject) Connection to MongoDB. Method resolution order: MongoCl ...
- stolon cloud native postgresql 高可用方案
stolon方案与patroni 类似,是一个新的pg ha 方案 包含的组件 keeper:它管理一个PostgreSQL实例,汇聚到由领导者sentinel计算的clusterview. sent ...
- Scaffold(Material库中提供的页面脚手架)知识点
Scaffold 包含:appBar.body.floatingActionButton
- Ant将Jmeter的jtl文件转为html文件报“前言中不允许有内容”
ant执行jmeter的脚本的时候提示“Fatal Error! 前言中不允许有内容” 解决办法: 在jmeter的bin目录中找到jmeter.properties: 将文件中#jmeter.sav ...