Updated comments and made sure style was consistent

This commit is contained in:
2020-07-10 13:36:16 -04:00
parent 7257a118d4
commit c72754dcf8
65 changed files with 1160 additions and 747 deletions

View File

@@ -1,11 +1,11 @@
//ProjectEuler/C++/Source/Problem22.cpp
//ProjectEuler/ProjectEulerCPP/Source/Problem22.cpp
//Matthew Ellison
// Created: 11-09-18
//Modified: 07-14-19
//Modified: 07-09-20
//What is the total of all the name scores in the file?
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
/*
Copyright (C) 2019 Matthew Ellison
Copyright (C) 2020 Matthew Ellison
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -32,6 +32,7 @@
#include "../Headers/Problem22.hpp"
//Holds the names that will be scored
std::vector<std::string> Problem22::names = { "MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY","KAREN",
"BETTY","HELEN","SANDRA","DONNA","CAROL","RUTH","SHARON","MICHELLE","LAURA","SARAH","KIMBERLY","DEBORAH","JESSICA","SHIRLEY",
"CYNTHIA","ANGELA","MELISSA","BRENDA","AMY","ANNA","REBECCA","VIRGINIA","KATHLEEN","PAMELA","MARTHA","DEBRA","AMANDA","STEPHANIE",
@@ -401,10 +402,7 @@ std::vector<std::string> Problem22::names = { "MARY","PATRICIA","LINDA","BARBARA
"KENETH","JACINTO","GRAIG","FRANKLYN","EDMUNDO","SID","PORTER","LEIF","JERAMY","BUCK","WILLIAN","VINCENZO","SHON","LYNWOOD","JERE",
"HAI","ELDEN","DORSEY","DARELL","BRODERICK","ALONSO"};
Problem22::Problem22() : Problem("What is the total of all the name scores in the file?"){
reserveVectors();
}
//Reserve the size of the vector to speed up insertion
void Problem22::reserveVectors(){
//Make sure the vector is the right size
sums.reserve(names.size());
@@ -414,6 +412,12 @@ void Problem22::reserveVectors(){
prod.resize(names.size());
}
//Constructor
Problem22::Problem22() : Problem("What is the total of all the name scores in the file?"){
reserveVectors();
}
//Solve the problem
void Problem22::solve(){
//If the problem has already been solved do nothing and end the function
if(solved){
@@ -445,6 +449,15 @@ void Problem22::solve(){
solved = true;
}
//Reset the problem so it can be run again
void Problem22::reset(){
Problem::reset();
sums.clear();
prod.clear();
reserveVectors();
}
//Return a string with the solution to the problem
std::string Problem22::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -472,10 +485,3 @@ uint64_t Problem22::getNameScoreSum() const{
}
return mee::getSum(prod);
}
void Problem22::reset(){
Problem::reset();
sums.clear();
prod.clear();
reserveVectors();
}