Quicksum


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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

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.

#include <iostream>
#include <string>
using namespace std;
int main(){
string s;
while(getline(cin, s)){
if(s[] == '#'){
break;
}
int l = s.length(), sum = ;
for(int i = ; i < l; i++){
if(s[i] != ' '){
int t = (int)(s[i] - 'A') + ;
sum += (i + ) * t;
//cout << t << " ";
}
}
cout << sum << endl;
}
return ;
}
 #include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream cin("aaa.txt");
char ch;
int i = ;
int sum = ;
//cin会忽略回车、空格、Tab跳格
//采用cin.get()一个一个读,就不会忽略任何字符
//也可采用cin.getline()一行一行读入
while(cin.get(ch)){
if(ch == '#') break;
if(ch != '\n'){
if(ch != ' ')
sum += i * (ch - );
i++;
}
if(ch == '\n'){
cout << sum << endl;
sum = ;
i = ;
}
}
return ;
}
 #include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream cin("aaa.txt");
char ch[];
int sum;
while(cin.getline(ch, )){
sum = ;
if(ch[] == '#')
break;
for(int i = ; ch[i] != '\0'; i++){
if(ch[i] != ' ')
sum += (i + ) * (ch[i] - );
}
cout << sum << endl;
}
return ;
}
Example Input: Example Output:
ACM
MID CENTRAL
REGIONAL PROGRAMMING CONTEST
ACN
A C M
ABC
BBC
#
46
650
4690
49
75
14
15

zoj 2812的更多相关文章

  1. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  2. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  3. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  4. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  5. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  6. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  7. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  8. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

  9. sqlserver 2008 建立订阅发布时 报错 解决方案 “错误 2812” 无法创建存储过程

    11月10日早上  一大早,还在地铁14号线上 ,接到同事给的信息 说我们的XX系统宕机了,本想没什么问题,一般服务器 只要硬件没有问题 重启一下就可以了, 但是事与愿违,偏偏最后检测到服务器磁盘阵列 ...

随机推荐

  1. 机器学习概念之特征选择(Feature selection)

    不多说,直接上干货! .

  2. WebStorm 10.0.3注册码

    UserName:William ===== LICENSE BEGIN ===== 45550-12042010 00001SzFN0n1bPII7FnAxnt0DDOPJA INauvJkeVJB ...

  3. 《Redis开发与运维》快速笔记(一)

    1.前言&基本介绍 在原始的系统架构中,我们都由程序直接连接DB,随着业务的进一步开展,DB的压力越来越大,为了缓解DB的这一压力,我们引入了缓存,在程序连接DB中加入缓存层, 从而减轻数据库 ...

  4. LN : leetcode 684 Redundant Connection

    lc 684 Redundant Connection 684 Redundant Connection In this problem, a tree is an undirected graph ...

  5. css 尺寸、边框、内边距、背景以及css Sprite

    上节课回顾: HTML标签: 格式排版 p 段落 双br 换行 单hr 分隔线 单h1~h6 标题 双pre 原样格式化输出 双div 标签,无任何特殊意义 HTML标签 :文本 <em> ...

  6. 洛谷P1251 餐巾计划问题(最小费用最大流)

    题意 一家餐厅,第$i$天需要$r_i$块餐巾,每天获取餐巾有三种途径 1.以$p$的费用买 2.以$f$的费用送到快洗部,并在$m$天后取出 3.以$s$的费用送到慢洗部,并在$n$天后取出 问满足 ...

  7. java实现单向链表的增、删、改、查

    单向链表 作者:vashon package com.ywx.link; /** * 单向链表 * @author vashon * */ public class LinkTest { public ...

  8. ref版的 摄像头 读取 因为id的时候,id不能重复 还要用时间戳,比较麻烦

    <!-- * @description 摄像头vue版实例 * @fileName cameraObject.vue * @author 彭成刚 * @date // :: * @version ...

  9. 【转】《windows核心编程》读书笔记

    这篇笔记是我在读<Windows核心编程>第5版时做的记录和总结(部分章节是第4版的书),没有摘抄原句,包含了很多我个人的思考和对实现的推断,因此不少条款和Windows实际机制可能有出入 ...

  10. 路由器wan口ip地址显示0.0.0.0怎么办

    http://m.xuexila.com/luyouqi/671049.html 这个网络时代里面我们最常用来连接网络的设备就是路由器了,现在的社会不管是工作还是生活几乎都离不开网络了,同时我们也要学 ...