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系统宕机了,本想没什么问题,一般服务器 只要硬件没有问题 重启一下就可以了, 但是事与愿违,偏偏最后检测到服务器磁盘阵列 ...
随机推荐
- vue项目node升级后,node-saas报错解决办法
ERROR in ./node_modules/_extract-text-webpack-plugin@3.0.2@extract-text-webpack-plugin/dist/loader.j ...
- iOS中数据类型转换--遇到则记录
1.NSString转NSNumber 使用情景:CoreData存储数据,其中一个为价格,CoreData里面定义为float 用文本输入框得到的数据类型是NSString,将NSString转换成 ...
- req.getParameter()无法获取参数(附前端json序列化)
问题:前端用Ajax的post方式想servlet传递参数,servlet的getParameter()方法无法获取参数. 前端代码: $.ajax({ url: '/TestWeb/addBook' ...
- (024)[工具软件]截屏录屏软件FSCapture(转)
该软件比 Snipaste 增加的功能有滚动截图和屏幕录制. 原文地址:https://www.appcgn.com/faststone-capture.html FastStoneCapture,简 ...
- Suricata的性能
不多说,直接上干货! 见官网 https://suricata.readthedocs.io/en/latest/performance/index.html Docs » 7. Performanc ...
- 玩ztree的一段代码
<!DOCTYPE HTML> <html lang="zh" xmlns:th="http://www.thymeleaf.org"> ...
- vim下ctrl + s 僵死问题的解决
vim下ctrl + s 僵死问题的解决 vim 使用vim习惯性手残Ctrl+S ,解决方法 : Ctrl + Q 就能恢复了
- EJB2的配置
1. ejb-jar.xml <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns=&q ...
- SQL Server之增删改操作
-------添加约束.增删改 use StudentDB2 go --------创建学生表--------- create table StudentInfo( --studentId int p ...
- 关于maven source1.5报错
是因为maven 默认是1.5编译的 <build>//加上这个配置,把编译给改掉试试 <pluginManagement> <plugins> <plugi ...