diff --git a/1_longest_substring_with_k_distinct_characters.cpp b/1_longest_substring_with_k_distinct_characters.cpp index 6aef394..64b36cb 100644 --- a/1_longest_substring_with_k_distinct_characters.cpp +++ b/1_longest_substring_with_k_distinct_characters.cpp @@ -24,6 +24,7 @@ struct semicolon_is_space : std::ctype { return &rc[0]; }; }; + class input { public: std::string s; @@ -33,9 +34,7 @@ public: }; std::istream &operator>>(std::istream &in, input &i) { - std::getline(in, i.s, '\n'); // An inelegant hack to skip newline character - std::getline(in, i.s, ';'); - in >> i.k; + in >> i.s >> i.k; return in; } @@ -128,10 +127,10 @@ int main(int argc, char *argv[]) { std::vector test_cases; semicolon_is_space delimeter; for (int i = 1; i < argc; i++) { - test_case t; std::ifstream f(argv[i]); f.imbue(std::locale(f.getloc(), new semicolon_is_space)); while (f.good()) { + test_case t; f >> t; if (t.i.s.length()) { // skip empty line/string inputs std::cout << t;