Quicksum解题报告
2012-04-09 17:35
148 查看
Quicksum
DescriptionA 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, andin 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, includingconsecutive 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 exampleQuicksum calculations for the packets "
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10341 | Accepted: 7132 |
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 = 650InputThe 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.OutputFor 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题目链接 http://poj.org/problem?id=3094
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){char a[27]={' ','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'},b[256];int i,j,s,sum=0;while(gets(b)&&b[0]!='#'){sum=0;s=strlen(b);for(i=0;i<s;i++){for(j=0;j<27;j++){if(b[i]==a[j]){sum+=(i+1)*j;}}}cout<<sum<<endl;}return 0;}
相关文章推荐
- POJ3094-Quicksum解题报告
- pku2243马棋到达最短路解题报告
- bzoj 3144 切糕 最小割 解题报告
- 智力题解题报告 No.4 9个点10个线
- poj解题报告——1837
- Leetcode 414. Third Maximum Number 第三大的数 解题报告
- codevs 1253 超级市场 DP 解题报告
- 智力题解题报告No.12 倒油 倒酒 倒水问题
- POJ 1068 解题报告
- Regional 2011, Asia - Kuala Lumpur 解题报告
- POJ1659 Frogs' Neighborhood ACM解题报告(图论基础 邻接矩阵)
- codevs 1766 装果子 二分 解题报告
- 【LeetCode】Substring with Concatenation of All Words 解题报告
- (解题报告)HDU2019---数列有序!
- 1034. Head of a Gang (30)解题报告
- UVa 12100 printer queue 解题报告
- LeetCode: Search Insert Position 解题报告
- 解题报告(LeetCode):Max Points on a Line
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2) 解题报告
- 解题报告:Prime Distance On Tree 点分治 + FFT