描述

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

#include <iostream>
#include <string>
using namespace std;
int main()
{
//freopen("a.txt","r",stdin);
string ch;
int i;
while(getline(cin,ch)&&ch[0]!='#')
{
int sum=0;
int len=strlen(ch.c_str());
for(i=0;i<len;i++)
{
if(ch[i]==' ') ch[i]='@';
sum+=(ch[i]-64)*(i+1);
}
cout<<sum<<endl; }
return 0;
}

  

1027-Quicksum的更多相关文章

  1. ACM——Quicksum

    Quicksum 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:615            测试通过:256 描述 A chec ...

  2. [字符哈希] POJ 3094 Quicksum

    Quicksum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16488   Accepted: 11453 Descri ...

  3. Light OJ 1027 - A Dangerous Maze (数学-期望)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1027 题目大意: 一个迷宫, 有n个门,选择一个门花费为|ai|, 如果选择的 ...

  4. (期望)A Dangerous Maze(Light OJ 1027)

    http://www.lightoj.com/volume_showproblem.php?problem=1027 You are in a maze; seeing n doors in fron ...

  5. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  6. Quicksum -SilverN

    quicksum Given a string of digits, find the minimum number of additions required for the string to e ...

  7. [bzoj 1027][JSOI2007]合金(解析几何+最小环)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1027 分析: 首先因为一个合金的和为1,所以考虑2个材料合金能否合成一个需求合金的时候 ...

  8. 【BZOJ】1027: [JSOI2007]合金(凸包+floyd)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1027 题意:$n$种材料,$m$种需求.每种材料有三个属性,给出三个属性的含量(和为1),问能否通过 ...

  9. PAT乙级 1027. 打印沙漏(20)

    1027. 打印沙漏(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求你写个程序把给定的符号打印成 ...

  10. 【BZOJ】【1027】【JSOI2007】合金

    计算几何/凸包/Floyd Orz rausen大爷太强辣 计算几何题目果然不会做>_> 这个题……虽然他给了3个坐标,但实际上是个二维的计算几何题= =因为第三维坐标可以直接用前两维坐标 ...

随机推荐

  1. Win7显示隐藏文件,隐藏文件夹怎么显示?如何查看?

    隐藏文件技术是木马病毒传播最惯用的手法之一,它们利用大部分网友对基础操作的不熟悉特点,逃过用户的发现和检查,显示隐藏文件的标准设置方法大家都会使用,一旦隐藏问题与病毒木马结合起来,比如典型的autor ...

  2. Linux c字符串中不可打印字符转换成16进制

    本文由 www.169it.com 搜集整理 如果一个C字符串中同时包含可打印和不可打印的字符,如果想将这个字符串写入文件,同时方便打开文件查看或者在控制台中打印出来不会出现乱码,那么可以将字符串中的 ...

  3. ios 多线程-GCD-NSOperation

    一.线程间的通讯 1.使用NSObject类的方法performSelectorInBackground:withObject:来创建一个线程. 具体的代码:隐式创建,自动启动 [Object per ...

  4. 使用WM_PASTE 和 WM_CHAR 消息时中文乱码总结

    当我们需要设置编辑框显示文本的时候,如果其它方式无法实现,可以试试WM_PASTE 和 WM_CHAR. 但使用这两种消息很容易出现中文乱码的情况,这一般是编码问题,可参考如下几点: 1,中文应采用U ...

  5. 更新Android SDK 访问谷歌等无需代理方法

    最近要做ANDROID,本来是想通过找镜像网址下载,发现公司网络屏蔽了,后来网络上搜索一圈,发现如下方法 1)更改HOST 2)使用代理 使用代理在公司的环境中属于违规操作,因此不能使用 只剩更改HO ...

  6. C# login with cookie and fiddler2

    http://blog.codeblack.nl/post/HttpWebRequest-HttpWebResponse-and-cookies.aspx CookieContainer cookie ...

  7. android 软件开机自启动

    安卓的很多功能实现方式都是“Don't call me, I'll call you back!”,开机启动就是其中之一 步骤: 1.首先建立一个BroadcastReceiver, 2.在他的onR ...

  8. [Linux]学习笔记(2)

    本节主要学习: whoami who am i who w users tty 6个命令的用法. (1)whoami whoami用于查询当前是以哪个用户登录Linux系统: [root@linuxf ...

  9. 《Java并发编程实战》读书笔记(更新中)

    一.简介 1.多线程编程要注意的几点: 安全性:永远不发生糟糕的事情 活跃性:某件正确的事情最终会发生(不会发生无限循环或者死锁) 性能:正确的事尽快发生(上下文切换消耗之类的) 二.线程安全 1.为 ...

  10. 1011. World Cup Betting (20)(最大值)

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...