Quicksum
来源:互联网 发布:2003版办公软件 编辑:程序博客网 时间:2024/05/21 10:17
题目描述
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 = 46MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 +
9*18 + 10*1 + 11*12 = 650
输入
输出
样例输入
ACMMID CENTRALREGIONAL PROGRAMMING CONTESTACNA C MABCBBC#
样例输出
46650469049751415
#include<stdio.h>
#include<stdlib.h>#include<string.h>
int main()
{
char a[999];
while(gets(a))
{
if(a[0]=='#')
break;
int sum=0,s;
for(int i=0;i<strlen(a);i++)
{
if(a[i]==' ')
s=0;
else
s=(a[i]-'A'+1);
sum=(i+1)*s+sum;
}
printf("%d\n",sum);
}
}
- Quicksum
- Quicksum
- QuickSum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- Quicksum
- hdu 2647
- mysql去空缺排序
- IP设置和网关设置
- 7.29 队列
- UVa 10325 The Lottery 【容斥】【入门】
- Quicksum
- SpringBoot13-springboot核心-基本配置
- Leetcode_80_Remove Duplicates from Sorted Array II
- 暴力求解法--生成子集
- 安卓源代码核心结构
- Android Fragment
- jQuery ajax中使用serialize() 方法提交表单数据
- 7.29 队列
- 触摸屏代码分析——优化措施