mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
Updated comments and made sure style was consistent
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/C++/Source/Problem17.cpp
|
||||
//ProjectEuler/ProjectEulerCPP/Source/Problem17.cpp
|
||||
//Matthew Ellison
|
||||
// Created: 10-05-18
|
||||
//Modified: 07-14-19
|
||||
//Modified: 07-09-20
|
||||
//If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
|
||||
//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
|
||||
@@ -30,11 +30,10 @@
|
||||
#include "../Headers/Problem17.hpp"
|
||||
|
||||
|
||||
//This is the largest number to get the words of
|
||||
int Problem17::TOP_NUM = 1000;
|
||||
|
||||
Problem17::Problem17() : Problem("If all the numbers from 1 to 1000 inclusive were written out in words, how many letters would be used?"), letterCount(0){
|
||||
}
|
||||
|
||||
//This function makes a word out of the number passed into it
|
||||
std::string Problem17::makeWord(int num){
|
||||
int currentDivider = 1000;
|
||||
int currentNum;
|
||||
@@ -142,6 +141,7 @@ std::string Problem17::makeWord(int num){
|
||||
return word;
|
||||
}
|
||||
|
||||
//This function helps makeWord() by returning the words for the numbers 1-9
|
||||
std::string Problem17::wordHelper(int num){
|
||||
std::string tempString;
|
||||
switch(num){
|
||||
@@ -159,6 +159,7 @@ std::string Problem17::wordHelper(int num){
|
||||
return tempString;
|
||||
}
|
||||
|
||||
//This counts the number of letters in the string that is passed in (ignoring numbers and punctuation)
|
||||
uint64_t Problem17::countLetters(std::string str){
|
||||
uint64_t letterCount = 0;
|
||||
//Step through every character in the string and count how many letters there are
|
||||
@@ -170,6 +171,11 @@ uint64_t Problem17::countLetters(std::string str){
|
||||
return letterCount;
|
||||
}
|
||||
|
||||
//Constructor
|
||||
Problem17::Problem17() : Problem("If all the numbers from 1 to 1000 inclusive were written out in words, how many letters would be used?"), letterCount(0){
|
||||
}
|
||||
|
||||
//Solve the problem
|
||||
void Problem17::solve(){
|
||||
//If the problem has already been solved do nothing and end the function
|
||||
if(solved){
|
||||
@@ -192,6 +198,13 @@ void Problem17::solve(){
|
||||
solved = true;
|
||||
}
|
||||
|
||||
//Reset the problem so it can be run again
|
||||
void Problem17::reset(){
|
||||
Problem::reset();
|
||||
letterCount = 0;
|
||||
}
|
||||
|
||||
//Return a string with the solution to the problem
|
||||
std::string Problem17::getString() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -202,6 +215,7 @@ std::string Problem17::getString() const{
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns the number of letters asked for
|
||||
uint64_t Problem17::getLetterCount() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -209,8 +223,3 @@ uint64_t Problem17::getLetterCount() const{
|
||||
}
|
||||
return letterCount;
|
||||
}
|
||||
|
||||
void Problem17::reset(){
|
||||
Problem::reset();
|
||||
letterCount = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user