Quicksum(poj 3094、水の題)

2493 ワード

/*
http://poj.org/problem?id=3094
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28938#problem/A
A-Quicksum
Time Limit:1000 MS    メモリLimit:65536 KB    64 bit IO Format:%I 64 d&%I 64 u
Submit
Status
Practice
POJ 3094
Description
A checksum is an algorithm ththat scans a packet of data and returns a single number.The ida isthaat the packet is changed、the chchecm will alsochage、so chchecksums artetetetetetetecting fortrtrtrininininininininstststststststststininininininininininininstststststststststststststststststststststststststinininininininininininininininininininininininininininininstststststststststststststststststaaaインダタ.
For this proble m,you will implement a checksum algorithm caled Quicksum.A Quicksum packet allows only upercase letters and spaces.It always begins and with and up percase letter.Othewise,sports cance
A Quicksum is the sum of the products of each charactr's position in the packet times the character's value.A spachas a value of zzz、while letters s have a value to theirposition the alphablet=Soeta.Soabet=1=atb=AAAAAtttta=AAAAfffffrerererererererererea=1=AAAAAAAAAAAAAAAAttttttttttttttttta=AAAAAAAAAAAAAAAAAAAAAAAMID CENTRAL」:
        ACM:1*1 + 2*3+3*13=46
MID CENTRAL:1*13+2*9+3*4+4*0+5+6*5+7*14+8*20+9*18+10*1+11*12=650
Input
The input consists of one or more packets followwed by a line containing only the that signals the end of the input.Each packet is on a line by、does not begin or end with a space、and conintor 255.rator。
Output
For each packet,output its Quicksum on a separate line in the output.
Sample Input
ACM
MID CENTRAL
REGIOAL PROGRAM MING CONTEST
ACN
A C
ABC
BBC
同前
Sample Output
46
650
4690
49
75
14
15
204 KB
0 ms
C++
428 B
2013-08-11
解析:
考え:水が多い問題は、文字ごとに対応する値があります。入力順に答えを出力すればいいです。
ここで注意して入力すればいいです。
*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=1000+10;
char s[maxn];
int main()
{ int i,j,sum;
  while(cin.getline(s,maxn))
  {
  	if(s[0]=='#')
  	 break;
  	 int sum=0;
  	 int len=strlen(s);
  	// printf("%d
",len); for(i=0;i<len;i++) { if(s[i]!=' ') { sum+=(i+1)*(s[i]-'A'+1); } } printf("%d
",sum); } return 0; }