refactoring
This commit is contained in:
+2
-15
@@ -1,3 +1,4 @@
|
||||
#include "../include/useful_funcs.h"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <errno.h>
|
||||
@@ -7,18 +8,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::string> splitString(const std::string &str) {
|
||||
std::istringstream iss(str);
|
||||
std::vector<std::string> words;
|
||||
std::string word;
|
||||
|
||||
while (iss >> word) {
|
||||
words.push_back(word);
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ifstream inputfile("input");
|
||||
std::string input;
|
||||
@@ -33,9 +22,7 @@ int main() {
|
||||
num_s = splitString(line);
|
||||
num.clear();
|
||||
|
||||
// Convert strings to integers
|
||||
std::transform(num_s.begin(), num_s.end(), std::back_inserter(num),
|
||||
[](const std::string &s) { return std::stoi(s); });
|
||||
CastStringVectorToIntVector(num_s, num);
|
||||
|
||||
// decreasing
|
||||
bool safe = true;
|
||||
|
||||
+2
-15
@@ -1,3 +1,4 @@
|
||||
#include "../include/useful_funcs.h"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <errno.h>
|
||||
@@ -7,18 +8,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::string> splitString(const std::string &str) {
|
||||
std::istringstream iss(str);
|
||||
std::vector<std::string> words;
|
||||
std::string word;
|
||||
|
||||
while (iss >> word) {
|
||||
words.push_back(word);
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
bool isSafe(const std::vector<int> &num, bool checkIncreasing) {
|
||||
for (size_t i = 1; i < num.size(); ++i) {
|
||||
int diff = checkIncreasing ? (num[i] - num[i - 1]) : (num[i - 1] - num[i]);
|
||||
@@ -61,9 +50,7 @@ int main() {
|
||||
num_s = splitString(line);
|
||||
num.clear();
|
||||
|
||||
// Convert strings to integers
|
||||
std::transform(num_s.begin(), num_s.end(), std::back_inserter(num),
|
||||
[](const std::string &s) { return std::stoi(s); });
|
||||
CastStringVectorToIntVector(num_s, num);
|
||||
|
||||
// Check safety with Problem Dampener support
|
||||
if (isSafeWithDampener(num)) {
|
||||
|
||||
Reference in New Issue
Block a user