注意:

  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. 【转】总结C++中取成员函数地址的几种方法

    转自:“http://www.cnblogs.com/nbsofer/p/get_member_function_address_cpp.html” 这里, 我整理了4种C++中取成员函数地址的方法, ...

  2. BIOS和CMOS【转载】

    在我们的电脑中,都有一块黑色的小芯片.但是请千万不要小看它,如果它损坏或者数据错误乱套的话,恭喜,如果不会“救回”这个小芯片,那么这台电脑可以挂闲鱼卖零件了……这个小芯片是什么呢?对,它就是BIOS芯 ...

  3. centos 6.5 安装mplayer

    https://centos.pkgs.org/6/linuxtech/mplayer-1.0.4-3.el6.x86_64.rpm.html

  4. HDU 6090 Rikka with Graph

    Rikka with Graph 思路: 官方题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  5. 你真的了解Spring Framework吗?

    Java 框架 上世纪90年代,使用Java开发Web应用普遍使用J2EE标准,J2EE具有平台无关性,对事务.消息等企业级的特性都有很好的支持,但当时的J2EE仍存在一些问题: 非常复杂:EJB的诞 ...

  6. ScoketTimeout Exception浅析

    以前都是用WebService的方式调用服务方的服务,此次直接调用别人的http服务. 使用的客户端是org.apache.http.client.HttpClient. 用的httpclient-4 ...

  7. SSH执行远程命令和传送数据

    $ ssh user@host 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub ...

  8. es-hadoop saveToEsWithMeta

    @Test def testEsRDDWriteWithDynamicMapping() { val doc1 = Map("one" -> null, "two& ...

  9. BZOJ1342 [Baltic2007]Sound静音问题

    越来越水了... 这道题是简单的单调队列,同时维护最大值和最小值即可. 另解:multiset大法求区间最大最小,但是复杂度会上升... /****************************** ...

  10. jsonp 跨域1

    今天上课学到了jsonp,看了理解,还需要多敲,代码贴出来看看 <!doctype html> <html> <head> <meta charset=&qu ...