Quicksum

摘要:
Quicksum时间限制:3000ms |内存限制:65535KB难度:2描述Achecksummary算法,可扫描数据并返回单个数字。他们的想法是,包装会发生变化,支票金额会发生变化

 

Quicksum

时间限制:3000 ms  |  内存限制:65535 KB
难度:2
 
描述

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 300 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<cstring>
#include<cstdio>
using namespace std;

int main()
{
  int str,i,k;
  char s[303];

  while(gets(s))
  {
    if(s[0]=='#')
  break;
 str=strlen(s);
 int sum=0;
 for(i=0;i<str;i++)
 {
   if(s[i]==' ') k=0; else k=(int)(s[i]-'@') ;
   sum+=(i+1)*k;
 }
 cout<<sum<<endl;
  }
  return 0;
}

免责声明:文章转载自《Quicksum》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇中文分词之结巴分词~~~附使用场景+demo(net)使用Nexus创建私服下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

”该证书已被签发机构吊销“错误解决方案

昨天安装和配置Outlook时,公司要求使用修改后的Outlook。在官网上下载安装证书后,始终没有成功,始终存在“证书已被颁发机构吊销”的错误,但很明显,证书尚未过期。一天下来,我对这件事很不高兴。我匆忙地把钥匙留在了公司,回家后,我决定不进门。SB房东说没有备用钥匙,让我找到开锁公司。开锁公司想打开我的烂门100次,所以我去网吧玩了一晚。今天早上我上班时...

SpringBoot项目中@Async方法没有执行的问题分析

现象:1.明显的现象:在日志文件中找不到方法中的日志输出,并且没有错误报告(即,未执行@Async标记的方法,也没有错误报告)。2.分析现象:日志中某段时间后没有任务xxx线程的日志原因:@Async异步方法默认使用Spring创建ThreadPoolTaskExecutor(参考TaskExecutionAutoConfiguration),其中默认核心线...

MySQL锁详解

MySQL锁详解update语句执行流程MySQL的锁介绍按照锁的粒度来说,MySQL主要包含三种类型(级别)的锁定机制:全局锁:锁的是整个database。由MySQL的SQLlayer层实现的表级锁:锁的是某个table。由MySQL的SQLlayer层实现的行级锁:锁的是某行数据,也可能锁定行之间的间隙。...

flutter 蓝牙开发记录

返回设备ID列表//您可以提前注册以扫描收听事件FlutterBlueflatterBlue=FlutterBlue。例子输出到uisetState((){this._blueDevice.add(r);防止多个扫描操作报告错误)FlutterBlueflatterBlue=FlutterBlue.instance;...

2.页面绘制和引入组件库uView

文本+背景色的形式,而不是横幅图的形式,可以节省未来的工作量。在index.vue中,关于开关的代码:EFGHIJKLMNOPQRSTUWXYZB˃DEFGHIJKLNNOPQRSTUVWXYZEFGHIJKLMNOPQRSTUVWXYZ导出默认值{data(){return{}},onLoad()},方法:{}}。横幅{width:100%;height:...

自定义样式滚动条

自定义IE浏览器滚动条样式追溯浏览器对滚动条的自定义,恐怕最早的就是IE浏览器了。感觉IE浏览器滚动条自定制功能并不是很强,只能控制一样显示各个部分的颜色而已,像宽度,结构等都无法控制,要靠出个性点的滚动条,很难!自定义FireFox浏览器滚动条在网上找了很多关于Firfox自定义浏览器滚动条的方法,发现firefox中却实是不支持的。...