Skip to content

Instantly share code, notes, and snippets.

@azyu
Created May 17, 2015 14:32
Show Gist options
  • Save azyu/345c6e98c1c24e875296 to your computer and use it in GitHub Desktop.
Save azyu/345c6e98c1c24e875296 to your computer and use it in GitHub Desktop.
#include <string>
#include <iostream>
#include <fstream>
#include <regex>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string names;
ifstream f("names.txt");
if(f.is_open())
{
while (f.good())
{
getline(f, names);
}
f.close();
}
cmatch res;
regex pattern("[A-Z]+");
sregex_token_iterator first (names.begin(), names.end(), pattern);
sregex_token_iterator last;
vector<string> words(first, last);
sort(words.begin(), words.end());
unsigned long score = 0;
for(auto i = 0; i < words.size(); ++i)
{
unsigned long localscore = 0;
string s = words[i];
for each( char c in s)
{
localscore += c - 'A' + 1;
}
score += localscore * ( i + 1 );
}
cout << score << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment