Last active
November 1, 2017 20:01
-
-
Save Rhernandez513/c04ad169513c0bacdaa6 to your computer and use it in GitHub Desktop.
This file contains 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
/* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
#include "io.h" | |
#include <iostream> | |
// GET INPUTS from STDIN | |
std::vector<std::string> Get_STDIN_Strings(void) { | |
std::string line; | |
std::vector<std::string> inputs; | |
while(std::getline(std::cin, line)) { inputs.push_back(line); } | |
return inputs; | |
} | |
===================================================================== | |
#include <iostream> | |
#include <sstream> | |
#include <vector> | |
#include <string> | |
#include <cstring> | |
#include "string-manip.h" | |
// Split string on a delimiter | |
std::vector<std::string> tokenizer(const std::string & p_pcstStr, char delim) { | |
std::vector<std::string> tokens; | |
std::istringstream mySstream(p_pcstStr); | |
std::string temp; | |
while(std::getline(mySstream, temp, delim)) { | |
tokens.push_back(temp); | |
} | |
return tokens; | |
} | |
// Vector of strings to Vector of Ints | |
std::vector<int> strings_to_ints(std::vector<std::string> vec) { | |
std::vector<int> tmp; | |
for (int i = 0, len = vec.size(); i < len ; ++i) { | |
tmp.push_back(std::stoi(vec[i])); | |
} | |
return tmp; | |
} | |
bool isInteger(const std::string & s) { | |
if(s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false ; | |
char * p ; | |
strtol(s.c_str(), &p, 10) ; | |
return (*p == 0) ; | |
} | |
// if d1 is earlier than d2 | |
// returns a value less than 0 | |
// | |
// 0 if both are the same date | |
// | |
// if d1 is later than d2. | |
// returns a value greater than 0 | |
int date_cmp(const char *d1, const char *d2) | |
{ | |
int rc; | |
// compare years | |
rc = strncmp(d1 + 6, d2 + 6, 4); | |
if (rc != 0) | |
return rc; | |
// compare months | |
rc = strncmp(d1 + 3, d2 + 3, 2); | |
if (rc != 0) | |
return rc; | |
// compare days | |
return strncmp(d1, d2, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment