POJ 3094

Quicksum

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14812   Accepted: 10322

Description

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.

Sample Input

ACM
MID CENTRAL
REGIONAL PROGRAMMING CONTEST
ACN
A C M
ABC
BBC
#

Sample Output

46
650
4690
49
75
14
15

CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)
#define MAX_N 255 + 10

using namespace std;

int main(){
    char s[MAX_N];
    while(gets(s + 1)){
        if(s[1] == ‘#‘) break;
        int l = strlen(s + 1);

        int ans = 0;
        REP(i, 1, l){
            if(s[i] == ‘ ‘) continue;
            ans += i * ((int)s[i] - ‘A‘ + 1);
        }

        printf("%d\n", ans);
    }
    return 0;
}
 
时间: 2024-10-22 23:00:19

POJ 3094的相关文章

[容斥原理] poj 3094 Sky Code

题目链接: http://poj.org/problem?id=3904 Sky Code Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1334   Accepted: 405 Description Stancu likes space travels but he is a poor software developer and will never be able to buy his own spacecraf

POJ 3094 Quicksum 难度:0

http://poj.org/problem?id=3094 1 #include<iostream> 2 #include <string> 3 using namespace std; 4 int main() 5 { 6 string str; 7 getline(cin,str); 8 while(str != "#") 9 { 10 int ans = 0; 11 for(int i = 0;i < str.length(); i++) 12 {

POJ - 3094 - Quicksum = 水题

http://poj.org/problem?id=3094 学习fgets的使用,注意fgets是会连换行一起保存的. #include<algorithm> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<map> #include<set> #include<stack> #include<

POJ 3094 Quicksum(简单题)

[题意简述]:题意很简单.看例子就能理解 [分析]:略.字符串的读取操作. // 200K 0Ms #include<iostream> using namespace std; int main() { char a[256]; while(1) { int sum = 0; gets(a); if(strcmp(a,"#")==0) break; int len = strlen(a); for(int i = 0;i<len;i++) { if(a[i] ==

POJ 3094 Quicksum(简单的问题)

[简要题意]:题意是非常easy. 看样能理解 [分析]:略. 读取字符串. // 200K 0Ms #include<iostream> using namespace std; int main() { char a[256]; while(1) { int sum = 0; gets(a); if(strcmp(a,"#")==0) break; int len = strlen(a); for(int i = 0;i<len;i++) { if(a[i] ==

poj 3094 Quicksum

#include <stdio.h> #include <string.h> char word[301]; int main() { int sum = 0; int i,len; while(gets(word)) { sum = 0; if(word[0] == '#') break; len = strlen(word); for(i = 0; i < len; ++i) { if(word[i] != ' ') sum += (i+1) * (word[i]-'A'

POJ题目分类推荐 (很好很有层次感)

著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递

POJ 刷题指南

OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递推. 构造法.(POJ 3295) 模拟法.(POJ 1068,POJ 2632,POJ 1573,POJ 2993,POJ 2996) 二

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive