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
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 = 46MID 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
源代码:
1 #include <iostream> 2 #include <cctype> 3 #include <string> 4 using namespace std; 5 6 int main() { 7 string aaa; int sum = 0; 8 while (getline(cin, aaa) && aaa != "#") { 9 for (int i = 1; i <= aaa.length(); i++) { 10 if (isalpha(aaa[i - 1])) sum += i * (aaa[i - 1] - 'A' + 1); 11 //cout << "sum["<<i<<"] "<<sum << endl; 12 } 13 cout << sum << endl; 14 sum = 0; 15 } 16 return 0; 17 }
转载于:https://www.cnblogs.com/QingHuan/p/4253658.html
TJU Problem 2520 Quicksum相关推荐
- TJU Problem 1065 Factorial
注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要. 原题: 1065. Factorial Time Limit: 1.0 Seconds Memory Limit ...
- TJU Problem 2857 Digit Sorting
原题: 2857. Digit Sorting Time Limit: 1.0 Seconds Memory Limit: 65536K Total Runs: 3234 Accepted ...
- TJU 2248. Channel Design 最小树形图
最小树形图,測模版.... 2248. Channel Design Time Limit: 1.0 Seconds Memory Limit: 65536K Total Runs: 2199 ...
- TJU 2248. Channel Design 最小树形图
最小树形图,測模版.... 2248. Channel Design Time Limit: 1.0 Seconds Memory Limit: 65536K Total Runs: 2199 ...
- ZOJ 2812 Quicksum
大家好,本篇内容讲解的是ZOJ ACM竞赛的编号为2812的题目 原题如下: A checksum is an algorithm that scans a packet of data and re ...
- linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.
所有的base 都要取消注释 mirrorlist 加上注释 另外所有的enable都要设为零 目录 今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现y ...
- A + B Problem
1001: A + B Problem Description 计算 A + B. Input 多组测试数据,每组测试数据占一行,包括2个整数. Output 在一行中输出结果. Sample Inp ...
- Error:(49, 1) A problem occurred evaluating project ':guideview'. Could not read script 'https://r
出现问题如下: Error:(49, 1) A problem occurred evaluating project ':guideview'. > Could not read script ...
- #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)
题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...
最新文章
- 使用Netty,我们到底在开发些什么?
- nginx 负载均衡的4种方式
- linux内存显示3.54g,为什么WDCP/linux服务器内存一直显示几乎用完了
- JQuery 和JavaScript的区别
- jQuery对象的序列化详解
- spark的三种运行模式以及yarn-client和yarn-cluster在提交命令上的区别
- EF关闭自动创建数据库表的方式
- 2017.3.22 小z的袜子 思考记录
- 键帽图纸_如何更换机械键盘的键帽(以便它可以永远存在)
- 网络操作系统之网络操作系统的功能
- 工程上为什么常用3dB带宽?而不是1dB或者2dB
- 如何保证投票公平_关于公平合理、简便省时的选举投票规则
- Android自定义LayoutManager第十一式之飞龙在天
- 终于解决“Git Windows客户端保存用户名与密码”的问题zhz
- ios 振动棒软件_iOS 14很棒
- 从零开始用人工智能预测股票(二、数据加工)
- 软件工程文档——步骤流程图
- 读书笔记—《销售铁军》随记6
- 会员计费系统c语言_c语言课程设计报告会员卡计费系统源代码
- 如何用源生js做出淘宝放大镜效果?