#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
char ch;
string strName;
vector<string> vecNameList;
while ( cin >> ch )
{
if ( ch >= 'A' && ch <= 'Z' )
{
strName.push_back( ch );
}
else
{
if ( !strName.empty() )
{
vecNameList.push_back( strName );
}
strName.clear();
}
}
if ( !strName.empty() )
{
vecNameList.push_back( strName );
}
sort( vecNameList.begin(), vecNameList.end() );
int nTotalScore = 0;
for ( int nPlace = 1; nPlace <= vecNameList.size(); ++nPlace )
{
string& str = vecNameList[nPlace-1];
int nValue = 0;
for ( size_t i = 0; i < str.length(); ++i )
{
nValue += str[i] - ('A' - 1);
}
nTotalScore += nValue * nPlace;
}
cout << nTotalScore << endl;
return 0;
}
http://projecteuler.net/problem=22 [Answer:871198282]
最新推荐文章于 2023-11-15 12:12:51 发布