注意:

  for (int i = 1; i <= aaa.length(); i++)

其中是“ i <= ",注意等号。

原题:

2520.   Quicksum


Time Limit: 0.5 Seconds   Memory Limit: 65536K
Total Runs: 2964   Accepted Runs: 1970

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 = 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 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.

Example Input: Example Output:
ACM
MID CENTRAL
REGIONAL PROGRAMMING
CONTEST
ACN
A C M
ABC
BBC
#
46
650
4690
49
75
14
15

Source: Mid-Central USA
2006

源代码:

 #include <iostream>
#include <cctype>
#include <string>
using namespace std; int main() {
string aaa; int sum = ;
while (getline(cin, aaa) && aaa != "#") {
for (int i = ; i <= aaa.length(); i++) {
if (isalpha(aaa[i - ])) sum += i * (aaa[i - ] - 'A' + );
//cout << "sum["<<i<<"] "<<sum << endl;
}
cout << sum << endl;
sum = ;
}
return ;
}

TJU Problem 2520 Quicksum的更多相关文章

  1. TJU Problem 2101 Bullseye

    注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...

  2. TJU Problem 2548 Celebrity jeopardy

    下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548.   Celebrity jeopardy Time Limit: 1.0 Seconds   Memory Lim ...

  3. TJU Problem 2857 Digit Sorting

    原题: 2857.   Digit Sorting Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 3234   Accepted ...

  4. TJU Problem 1015 Gridland

    最重要的是找规律. 下面是引用 http://blog.sina.com.cn/s/blog_4dc813b20100snyv.html 的讲解: 做这题时,千万不要被那个图给吓着了,其实这题就是道简 ...

  5. TJU Problem 1065 Factorial

    注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要. 原题: 1065.   Factorial Time Limit: 1.0 Seconds   Memory Limit ...

  6. TJU Problem 1100 Pi

    注: 1. 对于double计算,一定要小心,必要时把与double计算相关的所有都变成double型. 2. for (int i = 0; i < N; i++)         //N 不 ...

  7. TJU Problem 1090 City hall

    注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型. 原题: 1090.   City hall Time Limit: 1.0 Seconds   Memory ...

  8. TJU Problem 1644 Reverse Text

    注意: int N; cin >> N; cin.ignore(); 同于 int N; scanf("%d\n",&N); 另:关于 cin 与 scanf: ...

  9. uva 11525(线段树)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. S4 对象系统

    上一节中,我们介绍了 S3 系统.与大多数其他编程语言的面向对象系统不同,与那些类被定义为固定结构,且随着程序编译有确定的方法分派的系统相比,S3 系统显得非常不严谨.当我们定义一个 S3 类时,几乎 ...

  2. 引用类(RC)

    R 中还有一种具有引用语义的类系统,它更像其他面向对象编程语言中的类系统.首先,为了定义一个引用类( reference class , RC ),我们要给 setRefClass( )一个类定义.不 ...

  3. list_01

    双向链表 不支持随机存取([?] / at(?)) A.头尾 添加/移除 A.1.list::push_back(elemValue); A.2.list::pop_back(); A.3.list: ...

  4. java中的值传递和引用传递用法详解

    值传递:方法调用时,实际参数把它的值传递给对应的形式参数,方法执行中形式参数值的改变不影响实际参 数的值. 引用传递:也称为传地址.方法调用时,实际参数的引用(地址,而不是参数的值)被传递给方法中相对 ...

  5. js、jq对象互转

    1.js对象转jq对象:    $() $('#kw') $(document.getElementById("kw")) 2.jq对象转js对象: $(this).get(0) ...

  6. tomcat和java环境

    mac tomcat http://blog.csdn.net/huyisu/article/details/38372663 mac jdk 1.8 http://wlb.wlb.blog.163. ...

  7. Google chrome浏览器打不开网页,显示ERR_Failed...等问题的解决方法

    新装好的win7系统,打开Google浏览器,显示网页可能暂时无法连接,或者它已永久性的移动到了新地址.在网络搜索很多资料,发现解决方法如下,亲测成功. 原因,该服务依赖的TCP/IP 协议有问题. ...

  8. Zepto常见问题

    Zepto遇到的问题 延时 总所周知,默认click事件,会有300ms的延时问题,Zepto的tap事件很好的解决了这个问题.但是也挖了一个大坑. 点透 Zepto的点透应该也是大家比较熟悉的了.当 ...

  9. splay训练

    1, CF 455D 2, CF 420D 3, CF 414E

  10. POJ-3894 迷宫问题 (BFS+路径还原)

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...