注意:

  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. MyEclipse2014 优化设置

    1.指定本机java环境 Windows-->preferences-->java-->Insetallel JREs 右侧 单击ADD standard VM-->Next ...

  2. PHP标准库SPL

    SPL是Standard PHP Library(PHP标准库)的缩写.用来解决典型(常见)问题(common problems)的一组接口与类的集合 典型问题(common problems) - ...

  3. protected internal == internal

    总结:在同程序集下,protected internal类型修饰的成员变量可以在基类或派生类的类内.类外访问(同程序集下protected internal和internal访问性质相同,此处保留了i ...

  4. English trip -- VC(情景课) 7 C How much are the shose? 鞋多少钱

    Grammar focus 语法点: How much is ...? How much are...? How much is the shirt?    $15.99. How much are ...

  5. IntelliJ IDEA 阿里巴巴编码插件

    良好的编码习惯的从这个IDEA插件开始  这是根据阿里巴JAVA开发规范.PDF 开发的代码提示插件 具体提示如下   这里可以扫描你项目下不规范的代码 如果侧插件CPU太卡的话也可以点击右边的 ...

  6. LeetCode--058--最后一个单词的长度

    问题描述 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 说明:一个单词是指由字母组成,但不包含任何空格的字符串. 示例: 输入: ...

  7. LeetCode--027--移除元素

    问题描述: 给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间 ...

  8. python-day54--前端之js-DOM对象

    一.DOM对象 1.什么是HTML  DOM HTML  Document Object Model(文档对象模型---标签) 2.功能:定义了访问(查找)和操作HTML文档的标准方法 3.HTML ...

  9. Oracle数据库的“健康指示器”——事件(events)

    Oracle数据库“赢在”在架构,这话还是有道理的,除了锁(lock)这个最大的架构上的“赢点”之外,Oracle事件(event)也是另外一个很重要的架构上的“赢点”,因为当今的Oracle数据库, ...

  10. 判断回文字符串(c,python)

    回文字符串:一个字符串,不论是从左往右,还是从右往左,字符的顺序都是一样的(如abba,abcba等) 判断回文字符串比较简单,即用两个变量left,right模仿指针(一个指向第一个字符,一个指向最 ...