注意:

  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. VcCallC#_02

    1.VC代码:(vs2013运行正常) // ConsoleApplication_CallCS.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h&quo ...

  2. string_01

    内存释放和越界 越界:(1).复制越界,(2).取值越界 构造函数 (1).默认 空(无参) (2).拷贝(const string &) (3).带参数: const char * // Z ...

  3. Qt for Embedded Linux

    1. Qt for Embedded Linux http://doc.qt.io/qt-5/embedded-linux.html 2. Installing Qt for Embedded Lin ...

  4. 动态规划-最长可互除子序列 Largest Divisible Subset

    2018-08-28 17:51:04 问题描述: 问题求解: 本题是一个求最优解的问题,很自然的会想到动态规划来进行解决.但是刚开始还是陷入了僵局,直到看到了hint:LIS,才有了进一步的思路.下 ...

  5. mac外接显示器 双屏同时滑动问题

    问题:mac pro 外接一个显示器,用四个手指横向切换屏幕的时候,外接的显示器也一起跟着动了   解决:      

  6. (GoRails) Form对象设计风格: 用自建的Model来对参数进行操作。

    视频:https://gorails.com/episodes/form-objects-design-pattern?autoplay=1 git代码 :https://github.com/gor ...

  7. 3-15 《元编程》第6章 3-16 hook method

    Code That Writes Code 6.1 Coding your way to the weekend 6.2 Kernel#eval, Binding#eval Binding: Obje ...

  8. 『Pickle』数据结构持久化模块_常用方法记录

    可以把数据结构保存进文件并直接读出, 不论读取或者是保存,我们都需要借助open()函数,并且是二进制方式(‘wb’,‘rb’) json模块可以把字典结构改写为string然后保存,并可以反向读取字 ...

  9. Hadoop生产环境搭建(含HA、Federation)

    Hadoop生产环境搭建 1. 将安装包hadoop-2.x.x.tar.gz存放到某一目录下,并解压. 2. 修改解压后的目录中的文件夹etc/hadoop下的配置文件(若文件不存在,自己创建.) ...

  10. Ubuntu解压缩zip,tar,tar.gz,tar.bz2文件命令

    tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName .gz解压1:gunzip FileName.gz解压2:gzip -d FileN ...