-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22.cpp
39 lines (32 loc) · 808 Bytes
/
22.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
std::vector<std::string> split(const std::string& s, char delimiter)
{
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter))
{
tokens.push_back(token.substr(1,token.size() - 2));
}
return tokens;
}
int main(){
std::string name;
std::cin >> name;
std::vector<std::string> names = split(name,',');
std::sort(names.begin(),names.end());
int totalSum = 0;
for(int i = 1; i <= names.size(); i++){
int sum = 0;
for(char c : names[i-1]){
sum+= (c - 'A') + 1;
}
totalSum += sum*i;
}
std::cout << totalSum;
return 0;
}