zoj 2812
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的更多相关文章
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
- sqlserver 2008 建立订阅发布时 报错 解决方案 “错误 2812” 无法创建存储过程
11月10日早上 一大早,还在地铁14号线上 ,接到同事给的信息 说我们的XX系统宕机了,本想没什么问题,一般服务器 只要硬件没有问题 重启一下就可以了, 但是事与愿违,偏偏最后检测到服务器磁盘阵列 ...
随机推荐
- C#中Json的简单处理
命名空间:Windows.Data.Json在Windows Runtime中,可以使用Json类对获取的Json字符串进行操作,相比DataContractJsonSerializer类操作更加直观 ...
- 外文翻译 《How we decide》多巴胺的预言 第三节
这是第二章的最后一节. 书的导言 本章第一节 本章第二节 本节阅读感言:自我批评是自我提升的妙方. 多巴胺是我们感情的源泉.多巴胺相关的神经系统在不断的记录着我们主观意识没有注意到的一个个模式,将它们 ...
- Maximal Discount
Description: Linda is a shopaholic. Whenever there is a discount of the kind where you can buy three ...
- Java&Xml教程(十)XML作为属性文件使用
我们通常会将Java应用的配置参数保存在属性文件中,Java应用的属性文件可以是一个正常的基于key-value对,以properties为扩展名的文件,也可以是XML文件. 在本案例中,將会向大家介 ...
- SQL中的笛卡儿积问题和多表连接操作
(使用scott用户) SELECT * FROM scott.dept;--4SELECT * FROM scott.emp;--14 /**笛卡尔积内连接(等值连接)外连接(非等值连接)自连接*/ ...
- 移除sql数据所有链接用户
use master; go declare @temp nvarchar(20) declare myCurse cursor for select spid from sy ...
- qt 设置阴影 不显示黑色边框
this->setAttribute(Qt::WA_TranslucentBackground);
- SAP云平台架构概述
在我们开始SAP云平台的架构之旅之前,让我们先看看SAP已经发布的一些其他云产品.这些云产品方案可以分为公有云和私有云两种. SAP公有云解决方案见下图最右侧,比较著名的有SAP SuccessFac ...
- php-PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'xxx.so' in Unknown on line 0
关于xxx.so,今天在安装php的模块时候老是报,xxx.so的问题,虽然不影响使用,但作为一名当年的程序员强迫症患者,誓死要把 他搞清楚,后面发现是删除了也没有影响,因为在安装php的时候已经将他 ...
- MMRecovery下载和恢复方法教程
如何能下载到最新版本的恢复软件MMRecovery?下载后我们如何能够快速的使用起来呢?好的,我们接下来就开始这些内容. 一.下载最新版本的恢复软件MMRecovery 1.官方网站下载,如下图在浏览 ...