Here's my solution. It could easily be pulled down a bit, but its fun to work with .
Code:
#include <valarray>
#include <iostream>
#include <vector>
#include <numeric>
#include <cctype>
//Conversion
inline unsigned char convert( unsigned char ch ) { return tolower(ch) - 'a' + 1; }
int main( void )
{
std::vector< unsigned char > vec; //Need unsigned chars here so we don't overflow
unsigned char ch;
/* Debugging, make sure 'a' == 1
for( char ctest = 'a'; ctest <= 'z'; ++ctest )
std::cout << static_cast<int>(convert( ctest )) << " ";
std::cout << std::endl;*/
while( std::cin >> ch ) //Read until a non-number character pops in
{
if( !isalpha( ch ) ) break;
vec.push_back( convert(ch));
}
std::valarray<unsigned char> array(vec.begin(),vec.size()); //Create the powerful std::valarray for quick computation
array *= static_cast<unsigned char>(6); //Need to cast, otherwise, it thinks 6 is an int
int number = std::accumulate( &array[0], &array[array.size()], 0 ); //Add everthing together
std::cout << number << std::endl; //Output the sum
return 0;
}