From 660244227f8064fc55af84f55eace5d0725694f6 Mon Sep 17 00:00:00 2001 From: "Mr.Snoki" Date: Tue, 13 Dec 2022 20:40:36 +0300 Subject: [PATCH 1/4] Complite homework --- homework_01/task_01/src/utils.cpp | 36 +++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/homework_01/task_01/src/utils.cpp b/homework_01/task_01/src/utils.cpp index a6989bd..dc87da2 100644 --- a/homework_01/task_01/src/utils.cpp +++ b/homework_01/task_01/src/utils.cpp @@ -1,7 +1,39 @@ #include "utils.hpp" - +#include "iostream" #include std::vector SplitString(const std::string& data) { - return {}; + std::vector out; + size_t start; + size_t end = 0; + int flag = 0; + int begin = 0; + + while ((start = data.find_first_not_of(' ', end)) != std::string::npos) + { + if (data[end]==')'){ + flag = 0; + end += 1; + out.push_back(data.substr(begin, end - begin)); + continue; + } + if (flag == 1){ + end += 1; + continue; + } + if (data[start]=='('){ + begin = start; + flag = 1; + continue; + } + if (data[start]=='\t'){ + start += 1; + } + end = data.find(' ', start); + if (data.find('\t', start) < data.find(' ', start)){ + end = data.find('\t', start); + } + out.push_back(data.substr(start, end - start)); + } + return out; } From 9fa662b6e45b8087e90f922f0d0049ad43f5e0f3 Mon Sep 17 00:00:00 2001 From: "Mr.Snoki" Date: Thu, 15 Dec 2022 00:36:44 +0300 Subject: [PATCH 2/4] Complite homework --- homework_01/task_02/src/utils.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/homework_01/task_02/src/utils.cpp b/homework_01/task_02/src/utils.cpp index ebc7ffc..6bfa742 100644 --- a/homework_01/task_02/src/utils.cpp +++ b/homework_01/task_02/src/utils.cpp @@ -1,7 +1,28 @@ #include "utils.hpp" - #include int Calculate(const std::string& data) { - return 0; -} + int a, b, result; + result = 0; + a = data[0]-'0'; + b = data[2] - '0'; + switch (data[1]){ + case ('+'): + result = a + b; + return result; + break; + case ('-'): + result = a - b; + return result; + break; + case ('*'): + result = a * b; + return result; + break; + case ('/'): + result = a / b; + return result; + break; + } + return 0; +} \ No newline at end of file From 4565627740da402f8d5185da5c3c349397ecd00c Mon Sep 17 00:00:00 2001 From: "Mr.Snoki" Date: Sat, 17 Dec 2022 00:40:58 +0300 Subject: [PATCH 3/4] Homeworks fixed --- LICENSE | 12 ++++----- homework_01/task_01/src/utils.cpp | 43 ++++++++++++++++--------------- homework_01/task_02/src/utils.cpp | 9 ++++--- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/LICENSE b/LICENSE index 261eeb9..abebc40 100644 --- a/LICENSE +++ b/LICENSE @@ -35,7 +35,7 @@ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). + (an example is provided in the Appword_endix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the @@ -116,7 +116,7 @@ of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided + or as an addword_endum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. @@ -169,19 +169,19 @@ License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability + defword_end, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - END OF TERMS AND CONDITIONS + WORD_END OF TERMS AND CONDITIONS - APPENDIX: How to apply the Apache License to your work. + APPWORD_ENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a + comment syntax for the file format. We also recommword_end that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. diff --git a/homework_01/task_01/src/utils.cpp b/homework_01/task_01/src/utils.cpp index dc87da2..efb8022 100644 --- a/homework_01/task_01/src/utils.cpp +++ b/homework_01/task_01/src/utils.cpp @@ -1,39 +1,40 @@ #include "utils.hpp" -#include "iostream" + +#include #include std::vector SplitString(const std::string& data) { std::vector out; - size_t start; - size_t end = 0; - int flag = 0; - int begin = 0; + size_t word_start; + size_t word_end = 0; + bool in_brackets = false; + size_t opening_bracket = 0; - while ((start = data.find_first_not_of(' ', end)) != std::string::npos) + while ((word_start = data.find_first_not_of(' ', word_end)) != std::string::npos) { - if (data[end]==')'){ - flag = 0; - end += 1; - out.push_back(data.substr(begin, end - begin)); + if (data[word_end]==')'){ + in_brackets = false; + word_end += 1; + out.push_back(data.substr(opening_bracket, word_end - opening_bracket)); continue; } - if (flag == 1){ - end += 1; + if (in_brackets == 1){ + word_end += 1; continue; } - if (data[start]=='('){ - begin = start; - flag = 1; + if (data[word_start]=='('){ + opening_bracket = word_start; + in_brackets = 1; continue; } - if (data[start]=='\t'){ - start += 1; + if (data[word_start]=='\t'){ + word_start += 1; } - end = data.find(' ', start); - if (data.find('\t', start) < data.find(' ', start)){ - end = data.find('\t', start); + word_end = data.find(' ', word_start); + if (data.find('\t', word_start) < data.find(' ', word_start)){ + word_end = data.find('\t', word_start); } - out.push_back(data.substr(start, end - start)); + out.push_back(data.substr(word_start, word_end - word_start)); } return out; } diff --git a/homework_01/task_02/src/utils.cpp b/homework_01/task_02/src/utils.cpp index 6bfa742..855633a 100644 --- a/homework_01/task_02/src/utils.cpp +++ b/homework_01/task_02/src/utils.cpp @@ -1,4 +1,5 @@ #include "utils.hpp" + #include int Calculate(const std::string& data) { @@ -10,19 +11,19 @@ int Calculate(const std::string& data) { case ('+'): result = a + b; return result; - break; + case ('-'): result = a - b; return result; - break; + case ('*'): result = a * b; return result; - break; + case ('/'): result = a / b; return result; - break; + } return 0; } \ No newline at end of file From b4a9a3fbba5f934b8ffafc3f1754acec03653bf4 Mon Sep 17 00:00:00 2001 From: "Mr.Snoki" Date: Sat, 17 Dec 2022 08:22:55 +0300 Subject: [PATCH 4/4] Homework fixed --- homework_01/task_02/src/utils.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/homework_01/task_02/src/utils.cpp b/homework_01/task_02/src/utils.cpp index 855633a..d32b266 100644 --- a/homework_01/task_02/src/utils.cpp +++ b/homework_01/task_02/src/utils.cpp @@ -11,19 +11,15 @@ int Calculate(const std::string& data) { case ('+'): result = a + b; return result; - case ('-'): result = a - b; return result; - case ('*'): result = a * b; return result; - case ('/'): result = a / b; return result; - } return 0; } \ No newline at end of file