TJU Problem 2520 Quicksum
注意:
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
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的更多相关文章
- TJU Problem 2101 Bullseye
注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...
- TJU Problem 2548 Celebrity jeopardy
下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548. Celebrity jeopardy Time Limit: 1.0 Seconds Memory Lim ...
- TJU Problem 2857 Digit Sorting
原题: 2857. Digit Sorting Time Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 3234 Accepted ...
- TJU Problem 1015 Gridland
最重要的是找规律. 下面是引用 http://blog.sina.com.cn/s/blog_4dc813b20100snyv.html 的讲解: 做这题时,千万不要被那个图给吓着了,其实这题就是道简 ...
- TJU Problem 1065 Factorial
注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要. 原题: 1065. Factorial Time Limit: 1.0 Seconds Memory Limit ...
- TJU Problem 1100 Pi
注: 1. 对于double计算,一定要小心,必要时把与double计算相关的所有都变成double型. 2. for (int i = 0; i < N; i++) //N 不 ...
- TJU Problem 1090 City hall
注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型. 原题: 1090. City hall Time Limit: 1.0 Seconds Memory ...
- TJU Problem 1644 Reverse Text
注意: int N; cin >> N; cin.ignore(); 同于 int N; scanf("%d\n",&N); 另:关于 cin 与 scanf: ...
- uva 11525(线段树)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- Python day15装饰器基本理论,以及结合全局变量模拟session
装饰器(decorator):为其他函数添加附加功能 原则:1.不修改被修饰函数源代码 2.不修改被修饰函数的调用方式 装饰器=高阶函数+函数嵌套+闭包 import time def timmer( ...
- tryparse
[C#笔札]Tryparse的用法 这是参考读物的上得一个例子.自己仿照做的作业 private void button1_Click(object sender, EventArgs e) { ...
- English trip -- VC(情景课) 6 D
Read 阅读 Teresa‘s Day Treesa's is busy today. he meeting with her friend Joan is at 10:00. Her docto ...
- windows 命令巧用(持续更新)
netstat -ano netstat -anvb netstat -s -p [tcp|udp|ip|icmp] # 关闭/打开防火墙 netsh firewall set opmode disa ...
- Weird journey CodeForces - 788B (路径计数)
大意:$n$结点$m$条边无向图, 满足 $(1)$经过$m-2$条边$2$次 $(2)$经过其余$2$条边$1$次 的路径为好路径, 求所有好路径数 相当于边加倍后再删除两条边, 求欧拉路条数 首先 ...
- thinkphp得到客户端的ip
/** * 获取客户端IP地址 * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字 * @return mixed */function get_cli ...
- 贪心(二)NYOJ14题
#include <iostream> #include<cmath> #include "algorithm" using namespace std; ...
- sql 数据库显示 正在恢复
问题原因:Sql Server 一直显示正在恢复.有事务未恢复或者还原数据库造成 处理办法: 步骤一:数据库上右键->任务->分离 步骤二:数据库上右键->任务->脱机 数据库 ...
- 微信小程序通过js动态修改css样式的方法(交流QQ群:604788754)
WXML <view class="page" style="background-color:{{pageBackgroundColor}}" > ...
- learning uboot part command
=> part --helppart - disk partition related commands Usage:part uuid <interface> <dev> ...