Question 83: Quicksum

Source: Internet
Author: User

Print? Quicksum data consists of only 26 upper-case letters and spaces, and must start and end with an upper-case letter. In addition, Quicksum data can be any combination, including consecutive spaces.
 
Quicksum is the sum of the product of each letter location and letter value. The space value is 0, and the letter value is in alphabetical order, such as A = 1, B = 2, etc. The following is an example of "ACM" and "MID CENTRAL" computing Quicksum:
 
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 test data contains multiple groups of data. The input is ended #.
Each group of data occupies one row, not ending with spaces. Each row contains a maximum of 255 characters and only letters or spaces.
 
 
Output
 
For each group of data, a separate row outputs its Quicksum.
 

Quicksum data consists of only 26 upper-case letters and spaces, and must start and end with an upper-case letter. In addition, Quicksum data can be any combination, including consecutive spaces.

Quicksum is the sum of the product of each letter location and letter value. The space value is 0, and the letter value is in alphabetical order, such as A = 1, B = 2, etc. The following is an example of "ACM" and "MID CENTRAL" computing Quicksum:

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 test data contains multiple groups of data. The input is ended #.
Each group of data occupies one row, not ending with spaces. Each row contains a maximum of 255 characters and only letters or spaces.


Output

For each group of data, a separate row outputs its Quicksum.

 
[Plain]
# Include <stdio. h>
# Include <string. h>
 
Int main ()
{
Int I;
Int num;
Int sum;
Char str [255];
 
While (gets (str), str [0]! = '#')
{
Sum = 0;
Num = strlen (str );
 
For (I = 0; I <num; I ++)
{
If (str [I] = '')
{
Sum + = 0;
}
Else if (str [I]> = 'A' & str [I] <= 'Z ')
{
Sum + = (I + 1) * (str [I]-'A' + 1 );
}
}
 
Printf ("% d \ n", sum );
}
}

# Include <stdio. h>
# Include <string. h>

Int main ()
{
Int I;
Int num;
Int sum;
Char str [255];

While (gets (str), str [0]! = '#')
{
Sum = 0;
Num = strlen (str );

For (I = 0; I <num; I ++)
{
If (str [I] = '')
{
Sum + = 0;
}
Else if (str [I]> = 'A' & str [I] <= 'Z ')
{
Sum + = (I + 1) * (str [I]-'A' + 1 );
}
}

Printf ("% d \ n", sum );
}
}

 


Related Article

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.