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无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
随机推荐
- leetcode@ [124] Binary Tree Maximum Path Sum (DFS)
https://leetcode.com/problems/binary-tree-maximum-path-sum/ Given a binary tree, find the maximum pa ...
- IP查找工具——angry IP Scanner
作用] 若树莓派没有屏幕可通过该工具查找树莓派的IP地址.例如下图的树莓派IP地址可能为192.168.1.107. 图1 IP scan查找树莓派IP地址
- mlock家族:锁定物理内存
Start Page Index History Last Change mlock家族:锁定物理内存 系统调用 mlock 家族允许程序在物理内存上锁住它的部分或全部地址空间.这将阻止Linux 将 ...
- Android AndroidManifest 清单文件以及权限具体解释
每一个Android应用都须要一个名为AndroidManifest.xml的程序清单文件,这个清单文件名称是固定的而且放在每一个Android应用的根文件夹下.它定义了该应用对于Android系统来 ...
- (DP6.1.2.1)UVA 147 Dollars(子集和问题)
/* * UVA_147.cpp * * Created on: 2013年10月12日 * Author: Administrator */ #include <iostream> #i ...
- 【《Objective-C基础教程 》笔记ch05】(六)OC中的复合机制Composition
1.复合通过包括作为实例变量的的对象指针实现的. @interface Unicycle : NSObject { Pedal*pedal; ...
- ios开发——笔记篇
:开关 BOOL isopen = !isopen; //View @property (nonatomic, assign) BOOL open;//模型属性 self.group.open = ! ...
- 开源PaaS产品介绍
简介 本文主要介绍一下PaaS领域两个著名的开源软件: Cloud Foundry和OpenShift. [广告]如果你喜欢本博客,请点此查看本博客所有文章:http://www.cnblogs.co ...
- Windows7中Emacs 24 shell使用Gitbash
今天发现可以在shell中直接打开Gitbash,Gitbash提供了一些有用的Linux风格命令,最关键是我用emacs的时候不用再打开一个Gitbash终端操纵Git了. 在~/.emacs.d/ ...
- MySQL(17):Select-union(联合查询)使用注意事项
1. 需求: 获得0115班所有的代课教师代课天数,结果按照升序排序:同时获得0228班,结果按照降序排序. (1)首先查询原来的0115班和0228班所有代课天数,如下: (2)使用un ...