#include #include #include #include #include using namespace std; regex inputAStart {"\\d*-"}; regex inputAEnd {"-\\d*,"}; std::vector getNumbersFromString(const std::string& str) { std::vector numbers; std::stringstream ss(str); int number; while (ss >> number) numbers.push_back(number); return numbers; } void parseLine(string input, int* aStart, int* aEnd, int* bStart, int* bEnd) { smatch m; regex_search(input, m, inputAStart); string output = m[0].str(); output.pop_back(); *aStart = stoi(output); regex_search(input, m, inputAEnd); output = m[0].str(); output.pop_back(); output.erase(0,1); *aEnd = stoi(output); regex_search(input, m, regex(",\\d*")); output = m[0].str(); output.erase(0,1); *bStart = stoi(output); regex_search(input, m, regex("-\\d+$")); output = m.str(); output.erase(0,1); *bEnd = stoi(output); } bool isSubSet(int as, int ae, int bs, int be) { bool aInB = (as >= bs & ae <= be); bool bInA = (bs >= as & be <= ae); return (aInB | bInA); } bool isOverlapped(int as, int ae, int bs, int be) { return ((as >= bs & as <= be) | (bs >= as & bs <= ae)); } int main(int argc, char *argv[]) { string inputStr; ifstream inputFile(argv[1]); int pairs {0}; int overlaps {0}; while (getline(inputFile, inputStr)) { cout << endl << inputStr; int eAStart, eAEnd, eBStart, eBEnd; parseLine(inputStr, &eAStart, &eAEnd, &eBStart, &eBEnd); if (isSubSet(eAStart, eAEnd, eBStart, eBEnd)) { cout << "\tMATCHES\tOVERLAPPED"; pairs++; overlaps++; } else if (isOverlapped(eAStart, eAEnd, eBStart, eBEnd)) { cout << "\tOVERLAPPED"; overlaps++; } } cout << "\n\nPairs: " << pairs << "\nOverlaps: " << overlaps<< endl; }