ACM——Quicksum
Quicksum
总提交:615 测试通过:256
描述
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
输入
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.
输出
For each packet, output its Quicksum on a separate line in the output.
样例输入
ACM
MID CENTRAL
REGIONAL PROGRAMMING CONTEST
ACN
A C M
ABC
BBC
#
样例输出
46
650
4690
49
75
14
15
提示
题目来源
Mid-Central USA Region 2006
http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1027
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
string s;
ifstream in("./data.txt");
while(getline(in,s)){
cout<<s<<endl;
if(s=="#") return ;
int sum=;
for(size_t i=;i<s.length();i++)
{
if(s[i]!=' '){
sum+=(i+)*(s[i]-);
}
}
cout<<sum<<endl;
}
return ;
}
ACM——Quicksum的更多相关文章
- [字符哈希] POJ 3094 Quicksum
Quicksum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16488 Accepted: 11453 Descri ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- Quicksum
Quicksum Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Subm ...
- POJ3094 Quicksum
POJ3094 Quicksum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18517 Accepted: 1271 ...
- TJU Problem 2520 Quicksum
注意: for (int i = 1; i <= aaa.length(); i++) 其中是“ i <= ",注意等号. 原题: 2520. Quicksum Time L ...
- H - Quicksum(1.5.3)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...
- HDU.2734 Quicksum
Quicksum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
随机推荐
- ovirt user guide
Contents [hide] 1 Accessing the User Portal 1.1 Logging in to the User Portal 1.2 Logging out of t ...
- 第十三章、学习 Shell Scripts
什么是 Shell scripts shell script (程序化脚本) :shell script 是针对 shell 所写的『脚本!』 shell script 是利用 shell 的功能所写 ...
- wavecom短信猫常用AT命令
wavecom短信猫常用AT命令 一.一般命令 1. AT+CGMI 给出模块厂商的标识. 2. AT+CGMM 获得模块标识.这个命令用来得到支持的频带 (GSM 900,DCS 1800 或PCS ...
- mysql---where子查询、form子查询、exists子查询
1.什么是子查询? 当一个查询是另一个查询的条件时,称之为子查询. 2.子查询有什么好处? 子查询可以使用几个简单命令构造功能强大的复合命令. 那么,现在让我们一起来学习子查询. 3.where型的子 ...
- java正则表达式入门基础
一.正则表达式术语 1)元字符 : 非一般字符,具有某种意义的字符.如 : \bX : \b边界符, 以 X开始的单词 2) 常用 : \d : 匹配一个数字 : \d , 匹配至少一个以上数字 \ ...
- 学习 MFC之 工具栏(二)
对于InitToolBar()函数进行进一步解析: 1.首先声明一个全局对象: CToolBar m_toolbar; 2.然后用create()创建toolbar: //创建ToolBar工具条 ...
- 导出cluster log
将所有群集节点的日志导出到 clog 目录下: get-clusterlog -destination c:\clog 只导出前10分钟的群集日志: get-cluster -destination ...
- svn项目导入
svn项目导入 在已建立好svnserverserver的情况下.且所用电脑上已装好svn,在电脑上导入svn项目 首先,新建目录.点击鼠标右键,选择TortoiseSVN–>export 然后 ...
- 插头dp的几个模板
/* ural1519 求经过全部可行点的哈密顿回路的个数 括号匹配法,转移有点复杂,可是时间空间比較小 */ #include<cstdio> #include<cstring&g ...
- 开发腾讯移动游戏平台SDK ios版Ane扩展 总结
本文记录了在开发 腾讯移动游戏平台SDK(MSDK) ios版Ane扩展 过程中所遇到的问题 文中非常多问题都是基础的问题.对object c和xcode配置了解不深入导致的.(没办法,开发ane的程 ...