From f8c3ca0535704400ce32231553a6e6e7fbc9e4b4 Mon Sep 17 00:00:00 2001 From: nihonium Date: Wed, 2 Nov 2022 23:17:06 +0300 Subject: [PATCH] seminar04: fixes & 5 --- seminar04_templates/04_time/time.cpp | 11 ++--- seminar04_templates/04_time/time.h | 2 +- seminar04_templates/05_maximum/main.cpp | 34 +++++++++++++++ seminar04_templates/pairing_test.cpp | 55 ------------------------- 4 files changed, 39 insertions(+), 63 deletions(-) create mode 100644 seminar04_templates/05_maximum/main.cpp delete mode 100644 seminar04_templates/pairing_test.cpp diff --git a/seminar04_templates/04_time/time.cpp b/seminar04_templates/04_time/time.cpp index afc7c1d..335fdea 100644 --- a/seminar04_templates/04_time/time.cpp +++ b/seminar04_templates/04_time/time.cpp @@ -15,14 +15,11 @@ Time::Time(int hours, int minutes, int seconds) Time::Time(string_view s) { string buf; - buf[0] = s[0]; - buf[1] = s[1]; + buf = s.substr(0, 2); mHours = stoi(buf); - buf[0] = s[3]; - buf[1] = s[4]; + buf = s.substr(3, 2); mMinutes = stoi(buf); - buf[0] = s[6]; - buf[1] = s[7]; + buf = s.substr(6, 2); mSeconds = stoi(buf); } @@ -62,7 +59,7 @@ vector < Time > getTimesFromString(string_view s) return res; } -Time sumTimes(vector < Time > &v) +Time sumTimes(const vector < Time > &v) { Time res; for (int i = 0, size = v.size(); i < size; ++i) { diff --git a/seminar04_templates/04_time/time.h b/seminar04_templates/04_time/time.h index 68a4d92..f419c72 100644 --- a/seminar04_templates/04_time/time.h +++ b/seminar04_templates/04_time/time.h @@ -17,5 +17,5 @@ public: friend std::ostream& operator<<(std::ostream& out, Time t); }; -Time sumTimes(vector