Created
May 17, 2015 14:32
-
-
Save azyu/345c6e98c1c24e875296 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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