1388. quicksum

Source: Internet
Author: User

1388. quicksum

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 specified 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 examples
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 code of submission 909001, Zhongshan University Online Judge System#include<iostream>#include<string>using namespace std;int main(){    string str;    while( getline(cin,str) && str != "#" )    {        int sum=0;        for(int i=0;i<str.length();i++)        {            if(isalpha(str[i]))                sum+=(i+1)*(int(str[i]-64));        }        cout<<sum<<endl;    }    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.