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无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
随机推荐
- 10 steps to get Ruby on Rails running on Windows with IIS FastCGI- 摘自网络
Since the original tech preview release of FastCGI last year, we've been seeing a lot of requests fo ...
- 转载 ASP.NET MVC中使用ASP.NET Identity
转载原地址: http://blog.jobbole.com/90695/ 在之前的文章中,我为大家介绍了OWIN和Katana,有了对它们的基本了解后,才能更好的去学习ASP.NET Identit ...
- CSS链接、光标、DHTML、缩放
个属性 18.2 CSS中光标的使用(更详细可看文档) 属性名称 属性值 说明 cursor auto ...
- 消息队列数量统计(MSMQ,Performance Counter)
微软消息队列服务MSMQ (Microsoft Message Queue),工作在在线或者离线场景,并提供异步编程功能.互联网和企业开发很多场景应用,例如电商的订单处理流程,这是因为客户端不需要等待 ...
- 实现windows和linux互传文件
http://www.cnblogs.com/ylan2009/archive/2012/01/12/2321126.html 尝试从windows xp向ubuntu11.10传文件 ubuntu使 ...
- 转发 Mongodb 和 Hbase的区别
原始网址:http://hi.baidu.com/i1see1you/item/783a701f39a87549e75e06ea 1.Mongodb bson文档型数据库,整个数据都存在磁盘中,hba ...
- MinGW安装和使用总结
0.前言 最近对开源编译平台和编译器产生了兴趣,借博客平台总结一些东西(包括minGW,eclipse,sourcery和GDB调试等内容).总感觉时间一长某些东西自己都会忘记,过段时间回头看看自己的 ...
- 详解UML中的聚合,关联,泛化等关系
1. Overview UML设计类中,类的关系分为Generalization(泛化),Dependency(依赖关系).Association(关联关系).Aggregation(聚合关系).Co ...
- 复制带有random指针的单链表
如图1所示,有一条单链表,其节点除了有next指针外,还有一个random指针.random指针可指向单链表中的任意节点,包括它自身.random指针一旦指定,便不再更改.请设计算法,复制此单链表,并 ...
- linux和windows文件名称长度限制
Linux文件名称的长度限制是255个字符 windows下全然限定文件名称必须少于260个字符,文件夹名必须小于248个字符. linux下文件数.文件夹数.文件名称长度的各种限制 下面測试都是在没 ...