#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;

fstream file;
fstream file2;
string line;
vector<string> names;
int counter;

void SaveToFile(vector<string> a)
{
    file2.open("namessorted.txt");
    for(int i=0; i<a.size(); i++)
        file2 << a[i] << endl;
    file2.close();
}

void ReadNames(vector<string>& a)
{
    file.open("names.txt");

   while(getline(file,line))
    {
        stringstream   linestream(line);
        string         value;

        while(getline(linestream,value,','))
            a.push_back(value);

    }
file.close();
}

void ShowVector(vector<string> a)
{
    for(int i=0; i<a.size(); i++)
        cout << a[i] << endl;
}

void CountScores(vector<string> a)
{
    int couter = 1;
    int score = 0;
    unsigned long long int total = 0;
    char *tmp;

    for(int i=0; i<a.size(); i++)
    {
        memset(tmp, 0, 12);
        strcpy(tmp, a[i].c_str());
        for(int j=0; j<sizeof(tmp)*8; j++)
        {
            if(tmp[j]>=65 && tmp[j]<=90)
                score = score + (tmp[j]-64);
        }
    total = total + (score * (i+1));
    score = 0;
    }
    cout << total;
}

int main()
{
    ReadNames(names);
    //ShowVector(names);
    sort(names.begin(), names.end());
    //ShowVector(names);
    CountScores(names);
    //SaveToFile(names);
    return 0;
}


-----------------names.txt--------------------