# 11359: 【原1359】帮琪露诺加密

### 题目描述

author: SSY 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1359

## Description

ACEeA加密为：1×1 + 2×3 + 3×5 + 4×31 + 5×1= 151

## Sample Input

``````Welcome to SJTU
``````

## Sample Output

``````2748
``````

## BugenZhao's solution

``````//
// Created by BugenZhao on 2019/3/16.
//
// 编程练习

#include <iostream>
#include <cctype>

using namespace std;

int main() {
string str;
getline(cin, str);
long long ans = 0;
for (int i = 0; i < str.size(); ++i) {
if (str[i] == ' ') continue;
if (isupper(str[i]))
ans += (str[i] - 'A' + 1) * (i + 1);
else if (islower(str[i]))
ans += (str[i] - 'a' + 27) * (i + 1);
}
cout << ans << endl;
}
``````

## FineArtz's solution

``````/* 帮琪露诺加密 */
#include <iostream>
using namespace std;

int main(){
char ch;
int ans = 0, i = 0;
while (cin.get(ch)){
++i;
int p = 0;
if ((ch >= 'A') && (ch <= 'Z')) p = ch - 'A' + 1;
if ((ch >= 'a') && (ch <= 'z')) p = ch - 'a' + 27;
ans += p * i;
}
cout << ans << endl;
return 0;
}
``````

## q4x3's solution

``````/**
* 模拟
* 处理空格
**/
#include <iostream>
using namespace std;
int main()
{
string s;
int ans = 0;
getline(cin, s);
for (int i = 0;i < s.length();++ i) {
int tmp = s[i] - 'A' + 1;
if (tmp > 26) tmp = tmp - 6;
if (tmp < 0) tmp = 0;
ans += tmp * (i + 1);
}
cout << ans << endl;
}
``````

## skyzh's solution

``````#include <iostream>
#include <cstring>
using namespace std;

int main() {
int enc[256] = { 0 };
char msg[1000];

for (int i = 0; i < 26; i++) {
enc['A' + i] = i + 1;
}
for (int i = 0; i < 26; i++) {
enc['a' + i] = i + 27;
}

cin.getline(msg, 1000);
int l = strlen(msg);
int result = 0;

for (int i = 0; i < l; i++) {
result += (i + 1) * enc[msg[i]];
}

cout << result << endl;

return 0;
}
``````

## victrid's solution

``````#include <cstring>
#include <iostream>

using namespace std;

int pharse(char chz) {
if (chz == ' ')
return 0;
return chz - 'A' >= 26 ? chz - 'a' + 27 : chz - 'A' + 1;
}
int main() {
string chs;
int ans = 0;
getline(cin, chs);
for (int i = 0; chs[i] != '\0'; i++) {
ans += (i + 1) * pharse(chs[i]);
}
cout << ans;
return 0;
}
``````

## yyong119's solution

``````#include <cstdio>
using namespace std;
char ch;
int ans, cnt;
int main() {
ch = getchar();
while (ch != '\n') {
++cnt;
if (ch >= 'A' && ch <= 'Z')
ans += cnt * (ch - 'A' + 1);
else if (ch >= 'a' && ch <= 'z')
ans += cnt * (ch - 'a' + 27);
ch = getchar();
}
printf("%d", ans);
return 0;
}
``````