博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU------checksum
阅读量:6458 次
发布时间:2019-06-23

本文共 2229 字,大约阅读时间需要 7 分钟。

Quicksum

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3401 Accepted Submission(s): 2095
 
Problem 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 = 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
 
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
ACMMID CENTRALREGIONAL PROGRAMMING CONTESTACNA C MABCBBC#
 
Sample Output
46650469049751415
 
 
Source
Mid-Central USA 2006
 
Recommend
teddy
 
1 #include 
2 #include
3 4 int main() 5 { 6 char str[10000]; 7 int len,i,a[26],sum; 8 for(i = 0;i<26;i++) 9 {10 a[i] = i+1;11 }12 while(gets(str))13 {14 if(strcmp(str,"#") == 0)15 break;16 len = strlen(str);17 sum = 0;18 for(i = 0;i
='A' && str[i]<='Z')21 sum+=(i+1)*a[str[i]-'A'];22 }23 printf("%d\n",sum);24 }25 26 return 0;27 }

 

转载于:https://www.cnblogs.com/MICE1024/p/5775603.html

你可能感兴趣的文章
Redis详解
查看>>
论程序员加班的害处
查看>>
codeblocks快捷键
查看>>
基于HTML5的WebGL设计汉诺塔3D游戏
查看>>
WPF资料链接
查看>>
过滤DataTable表中的重复数据
查看>>
再次更新
查看>>
mysql的数据类型int、bigint、smallint 和 tinyint取值范围
查看>>
利用网易获取所有股票数据
查看>>
移动铁通宽带上网设置教程
查看>>
Python算法(含源代码下载)
查看>>
利用Windows自带的Certutil查看文件MD5
查看>>
通过原生js添加div和css
查看>>
简单的导出表格和将表格下载到桌面上。
查看>>
《ArcGIS Engine+C#实例开发教程》第一讲桌面GIS应用程序框架的建立
查看>>
查询指定名称的文件
查看>>
Python 嵌套列表解析
查看>>
[GXOI/GZOI2019]旧词——树链剖分+线段树
查看>>
anroid 广播
查看>>
AJAX POST&跨域 解决方案 - CORS
查看>>