From 05c6a0a855b728630879f9cf82eface80fea737b Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 22 Oct 2022 08:16:47 +0000 Subject: [PATCH 1/5] first commit --- homework_01/task_01/src/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homework_01/task_01/src/utils.cpp b/homework_01/task_01/src/utils.cpp index a6989bd..75a6ca9 100644 --- a/homework_01/task_01/src/utils.cpp +++ b/homework_01/task_01/src/utils.cpp @@ -3,5 +3,5 @@ #include std::vector SplitString(const std::string& data) { - return {}; + return {data}; } From 7e91fd4f0d18357b4b686c912bd1435dc71b2d63 Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 12 Nov 2022 08:26:56 +0000 Subject: [PATCH 2/5] wip --- homework_01/task_01/src/main.cpp | 10 +- homework_01/task_01/src/utils.cpp | 41 +++++++- homework_01/task_02/src/main.cpp | 30 +++++- homework_01/task_02/src/utils.cpp | 160 +++++++++++++++++++++++++++++- homework_01/task_02/src/utils.hpp | 5 + 5 files changed, 236 insertions(+), 10 deletions(-) diff --git a/homework_01/task_01/src/main.cpp b/homework_01/task_01/src/main.cpp index 0b3dcb2..ff7c495 100644 --- a/homework_01/task_01/src/main.cpp +++ b/homework_01/task_01/src/main.cpp @@ -3,8 +3,14 @@ #include int main() { - for (const auto& word : SplitString("asdas das das fgag (adasd 1fas)")) { - std::cout << word << "\n"; + std::string line; + /*std::getline(std::cin, line); + for (const auto& word : SplitString(line)) { + std::cout << word << '\n'; + }*/ + line="a\na\ta a"; + for (const auto& word : SplitString(line)) { + std::cout << word << '\n'; } return 0; } diff --git a/homework_01/task_01/src/utils.cpp b/homework_01/task_01/src/utils.cpp index 75a6ca9..44f52b8 100644 --- a/homework_01/task_01/src/utils.cpp +++ b/homework_01/task_01/src/utils.cpp @@ -1,7 +1,44 @@ #include "utils.hpp" -#include +#include +#include +#include +#include +#include +using namespace std; std::vector SplitString(const std::string& data) { - return {data}; + std::vector v; + std::string buff = ""; + bool flag = false; //скобки закрыты (или их нет) + cout << size(data) << endl; + for (int i = 0; i < size(data); ++i) { + if (data[i] == '(') { + flag = true; //скобки открыты + } else if (data[i] == ')') { + flag = false; //скобки закрыты + } + if (((data[i] != ' ') and (data[i] != '\t')) or (flag == true)) { + buff += data[i]; + } + cout << "Data" << i << " : " << data[i] << endl; + cout << "Buff: " << buff << endl; + if (flag == false) { + if ((data[i] == ' ') or (data[i] == '\t') or (i + 1 >= size(data))) { + if (buff != "") { + v.push_back(buff); + buff = ""; + } + } + } else { + if (i + 1 >= size(data)) { + if (buff != "") { + v.push_back(buff); + buff = ""; + } + } + } + } + std::cout << "Size of vector: " << v.size() << "\n"; + return v; } diff --git a/homework_01/task_02/src/main.cpp b/homework_01/task_02/src/main.cpp index 72a6f13..39a6120 100644 --- a/homework_01/task_02/src/main.cpp +++ b/homework_01/task_02/src/main.cpp @@ -1,10 +1,32 @@ #include - +#include +#include +#include +#include #include - +#include +using namespace std; int main() { - std::string data; + /*std::string data; std::getline(std::cin, data); std::cout << Calculate(data); - return 0; + return 0;*/ + //eherh832759328623626 +string input; +int res; +while(7){ + + std::cout << "Vvedite, poghaluista, stroku: " << std::endl; + getline(cin,input); + if (input=="quit") + { + break; + } + cout< #include +#include +#include +#include +#include +using namespace std; -int Calculate(const std::string& data) { - return 0; +std::vector SplitString(const std::string& data) { + std::vector v; + std::string buff=""; + bool flag=false; + cout<=size(data))) + { + if (buff!="") + { + v.push_back(buff); + buff=""; + } + } + } + else + { + if (i+1>=size(data)) + { + if (buff!="") + { + v.push_back(buff); + buff=""; + } + } + } + } + //std::cout << "Size of vector: "<='0') && (str[i]<='9'))/* if (std::isdigit(str[i]))*/a=1; + else flag = false; + + if ((!std::isdigit(str[0])) && (str[0]!='-') && (str[0]!='+')) + { + flag = false; + } +} +return flag; +} + +bool IsInt(const std::string& str) +{ + static std::regex r(R"([+-]?\d+)"); // проверяем число ли это в системе regular expressions (regex) + return std::regex_match(str,r); +} + +bool IsDouble(const std::string& str) +{ + static std::regex r(R"([+-]?(\d*\.)?\d+([Ee][+-]?\d+)?)"); // проверяем double число ли это в системе regular expressions (regex) + return std::regex_match(str,r); +} + +string Parce(const std::string& input) { + bool Int_test=IsInt(input); + if (Int_test) {return "true"; + std:cout< chisla; +vector r= SplitString(data); +for (int i=0;i='0') && (data[i]<='9')) + { + + } +for (i=0;i int Calculate(const std::string& data); +std::vector SplitString(const std::string& data); +bool IsInt_bad_version(const std::string& str); +bool IsInt(const std::string& str); +bool IsDouble(const std::string& str); +std::string Parce(const std::string& input); \ No newline at end of file From 05613cf2f9c204f71232023972d389d56aecd133 Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 23 Nov 2022 16:12:04 +0000 Subject: [PATCH 3/5] final homework 1 --- homework_01/task_02/src/main.cpp | 40 ++--- homework_01/task_02/src/utils.cpp | 279 ++++++++++++++++-------------- 2 files changed, 168 insertions(+), 151 deletions(-) diff --git a/homework_01/task_02/src/main.cpp b/homework_01/task_02/src/main.cpp index 39a6120..f0b65d0 100644 --- a/homework_01/task_02/src/main.cpp +++ b/homework_01/task_02/src/main.cpp @@ -1,32 +1,22 @@ +#include + #include +#include #include -#include -#include -#include #include -#include using namespace std; int main() { - /*std::string data; - std::getline(std::cin, data); - std::cout << Calculate(data); - return 0;*/ - //eherh832759328623626 -string input; -int res; -while(7){ - - std::cout << "Vvedite, poghaluista, stroku: " << std::endl; - getline(cin,input); - if (input=="quit") - { - break; + string input; + int res; + cout << "REZULTAT" << Calculate("5*9-8") << endl; + while (7) { + std::cout << "Vvedite, poghaluista, stroku: " << std::endl; + getline(cin, input); + if (input == "quit") { + break; + } + cout << Parce(input) << endl; + cout << "Double: " << IsDouble(input) << endl; } - cout< + #include +#include #include -#include -#include #include -#include +#include using namespace std; std::vector SplitString(const std::string& data) { - std::vector v; - std::string buff=""; - bool flag=false; - cout< v; + std::string buff = ""; + bool flag = false; + for (int i = 0; i < size(data); ++i) { + if (data[i] == '(') { + flag = true; + } else if (data[i] == ')') { + flag = false; } - if (((data[i]!=' ') and (data[i]!='\t')) or (flag==true)) - { - buff+=data[i]; + if (((data[i] != ' ') and (data[i] != '\t') and (data[i] != '+') and + (data[i] != '-') and (data[i] != '*') and (data[i] != '/')) or + (flag == true)) { + buff += data[i]; } - if (flag==false) - { - if ((data[i]==' ') or (data[i]=='\t') or (i+1>=size(data))) - { - if (buff!="") - { + if (flag == false) { + if ((data[i] == ' ') or (data[i] == '\t') or (data[i] == '+') or + (data[i] == '-') or (data[i] == '*') or (data[i] == '/') or + (i + 1 >= size(data))) { + if (buff != "") { v.push_back(buff); - buff=""; + buff = ""; + if ((data[i] == '+') or (data[i] == '-') or (data[i] == '*') or + (data[i] == '/')) { + buff += data[i]; + v.push_back(buff); + buff = ""; + } } } - } - else - { - if (i+1>=size(data)) - { - if (buff!="") - { + } else { + if (i + 1 >= size(data)) { + if (buff != "") { v.push_back(buff); - buff=""; + buff = ""; } } } } - //std::cout << "Size of vector: "<='0') && (str[i]<='9'))/* if (std::isdigit(str[i]))*/a=1; - else flag = false; +bool IsInt_bad_version(const std::string& str) { + int a = 1; + bool flag = true; + if (str.empty()) flag = false; + for (size_t i = 1; i < str.size(); ++i) { + if ((str[i] >= '0') && (str[i] <= '9')) + a = 1; + else + flag = false; - if ((!std::isdigit(str[0])) && (str[0]!='-') && (str[0]!='+')) - { - flag = false; + if ((!std::isdigit(str[0])) && (str[0] != '-') && (str[0] != '+')) { + flag = false; + } } -} -return flag; + return flag; } -bool IsInt(const std::string& str) -{ - static std::regex r(R"([+-]?\d+)"); // проверяем число ли это в системе regular expressions (regex) - return std::regex_match(str,r); +bool IsInt(const std::string& str) { + static std::regex r(R"([+-]?\d+)"); // проверяем число ли это в системе + // regular expressions (regex) + return std::regex_match(str, r); } -bool IsDouble(const std::string& str) -{ - static std::regex r(R"([+-]?(\d*\.)?\d+([Ee][+-]?\d+)?)"); // проверяем double число ли это в системе regular expressions (regex) - return std::regex_match(str,r); +bool IsDouble(const std::string& str) { + static std::regex r( + R"([+-]?(\d*\.)?\d+([Ee][+-]?\d+)?)"); // проверяем double число ли это в + // системе regular expressions + // (regex) + return std::regex_match(str, r); } string Parce(const std::string& input) { - bool Int_test=IsInt(input); - if (Int_test) {return "true"; - std:cout< chisla; -vector r= SplitString(data); -for (int i=0;i='0') && (data[i]<='9')) - { - - } -for (i=0;i chisla; + vector r = SplitString(data); + for (int i = 0; i < r.size(); ++i) { + std::cout << i << "element: " << r[i] << '\n'; } - if (znak==1) - { - rez-=chisla[i]; + for (i = 0; i < data.size(); ++i) { + if ((data[i] >= '0') && (data[i] <= '9')) { + } + for (i = 0; i < r.size(); ++i) { + if ((r[i] != "+") and (r[i] != "-") and (r[i] != "*") and (r[i] != "/")) { + chisla.push_back(stoi(r[i])); + } else { + znak = r[i]; + } + } + if (!chisla.empty()) + rez = chisla[0]; + else { + cout << "Error" << endl; + rez = -1; + } + cout << znak << endl; + if (!chisla.empty()) { + for (i = 1; i < chisla.size(); ++i) { + if (znak == "+") { + rez += chisla[i]; + } + if (znak == "-") { + rez -= chisla[i]; + } + if (znak == "*") { + rez *= chisla[i]; + } + if (znak == "/") { + rez /= chisla[i]; + } + } + } + return rez; } - if (znak==2) - { - rez/=chisla[i]; +} + +int CalculatePrefix(const std::string& data) { + cout << "Not Ready" << endl; + int i = 0; + int buff_int = 0; + std::string znak; + int rez = 0; + // std::string buff_str; + vector chisla; + vector r = SplitString(data); + for (int i = 0; i < r.size(); ++i) { + std::cout << i << "element: " << r[i] << '\n'; } - if (znak==3) - { - rez*=chisla[i]; + for (i = 0; i < data.size(); ++i) { + if ((data[i] >= '0') && (data[i] <= '9')) { + } + for (i = 0; i < r.size(); ++i) { + if ((r[i] != "+") and (r[i] != "-") and (r[i] != "*") and (r[i] != "/")) { + chisla.push_back(stoi(r[i])); + } else { + znak = r[i]; + } + } + if (!chisla.empty()) + rez = chisla[0]; + else { + cout << "Error" << endl; + rez = -1; + } + cout << znak << endl; + if (!chisla.empty()) { + for (i = 1; i < chisla.size(); ++i) { + if (znak == "+") { + rez += chisla[i]; + } + if (znak == "-") { + rez -= chisla[i]; + } + if (znak == "*") { + rez *= chisla[i]; + } + if (znak == "/") { + rez /= chisla[i]; + } + } + } + return rez; } } -} -return rez; -} -} - - - - From 4baf0dab367e30bc737a214de1d1dfb4d8904d2d Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 23 Nov 2022 16:43:59 +0000 Subject: [PATCH 4/5] solved tasks 1 and 2 --- homework_01/task_01/src/main.cpp | 7 +- homework_01/task_01/src/utils.cpp | 8 +- homework_01/task_02/src/main.cpp | 16 +--- homework_01/task_02/src/utils.cpp | 145 +++++------------------------- homework_01/task_02/src/utils.hpp | 4 - 5 files changed, 29 insertions(+), 151 deletions(-) diff --git a/homework_01/task_01/src/main.cpp b/homework_01/task_01/src/main.cpp index ff7c495..24c8952 100644 --- a/homework_01/task_01/src/main.cpp +++ b/homework_01/task_01/src/main.cpp @@ -1,16 +1,11 @@ #include - #include int main() { std::string line; - /*std::getline(std::cin, line); + line = "a\na\ta a"; for (const auto& word : SplitString(line)) { std::cout << word << '\n'; - }*/ - line="a\na\ta a"; - for (const auto& word : SplitString(line)) { - std::cout << word << '\n'; } return 0; } diff --git a/homework_01/task_01/src/utils.cpp b/homework_01/task_01/src/utils.cpp index 44f52b8..cd30430 100644 --- a/homework_01/task_01/src/utils.cpp +++ b/homework_01/task_01/src/utils.cpp @@ -11,7 +11,7 @@ std::vector SplitString(const std::string& data) { std::vector v; std::string buff = ""; bool flag = false; //скобки закрыты (или их нет) - cout << size(data) << endl; + // cout << size(data) << endl; for (int i = 0; i < size(data); ++i) { if (data[i] == '(') { flag = true; //скобки открыты @@ -21,8 +21,8 @@ std::vector SplitString(const std::string& data) { if (((data[i] != ' ') and (data[i] != '\t')) or (flag == true)) { buff += data[i]; } - cout << "Data" << i << " : " << data[i] << endl; - cout << "Buff: " << buff << endl; + // cout << "Data" << i << " : " << data[i] << endl; + // cout << "Buff: " << buff << endl; if (flag == false) { if ((data[i] == ' ') or (data[i] == '\t') or (i + 1 >= size(data))) { if (buff != "") { @@ -39,6 +39,6 @@ std::vector SplitString(const std::string& data) { } } } - std::cout << "Size of vector: " << v.size() << "\n"; + // std::cout << "Size of vector: " << v.size() << "\n"; return v; } diff --git a/homework_01/task_02/src/main.cpp b/homework_01/task_02/src/main.cpp index f0b65d0..548ee13 100644 --- a/homework_01/task_02/src/main.cpp +++ b/homework_01/task_02/src/main.cpp @@ -5,18 +5,4 @@ #include #include using namespace std; -int main() { - string input; - int res; - cout << "REZULTAT" << Calculate("5*9-8") << endl; - while (7) { - std::cout << "Vvedite, poghaluista, stroku: " << std::endl; - getline(cin, input); - if (input == "quit") { - break; - } - cout << Parce(input) << endl; - cout << "Double: " << IsDouble(input) << endl; - } - return 0; -} +int main() { return 0; } diff --git a/homework_01/task_02/src/utils.cpp b/homework_01/task_02/src/utils.cpp index 00b524e..c819e1a 100644 --- a/homework_01/task_02/src/utils.cpp +++ b/homework_01/task_02/src/utils.cpp @@ -51,140 +51,41 @@ std::vector SplitString(const std::string& data) { return v; } -bool IsInt_bad_version(const std::string& str) { - int a = 1; - bool flag = true; - if (str.empty()) flag = false; - for (size_t i = 1; i < str.size(); ++i) { - if ((str[i] >= '0') && (str[i] <= '9')) - a = 1; - else - flag = false; - - if ((!std::isdigit(str[0])) && (str[0] != '-') && (str[0] != '+')) { - flag = false; - } - } - return flag; -} - -bool IsInt(const std::string& str) { - static std::regex r(R"([+-]?\d+)"); // проверяем число ли это в системе - // regular expressions (regex) - return std::regex_match(str, r); -} - -bool IsDouble(const std::string& str) { - static std::regex r( - R"([+-]?(\d*\.)?\d+([Ee][+-]?\d+)?)"); // проверяем double число ли это в - // системе regular expressions - // (regex) - return std::regex_match(str, r); -} - -string Parce(const std::string& input) { - bool Int_test = IsInt(input); - if (Int_test) { - return "true"; - std: - cout << std::stod(input) << std::endl; - } else - return "false"; -} - int Calculate(const std::string& data) { int i = 0; int buff_int = 0; std::string znak; int rez = 0; - // std::string buff_str; vector chisla; vector r = SplitString(data); - for (int i = 0; i < r.size(); ++i) { - std::cout << i << "element: " << r[i] << '\n'; - } - for (i = 0; i < data.size(); ++i) { - if ((data[i] >= '0') && (data[i] <= '9')) { - } - for (i = 0; i < r.size(); ++i) { - if ((r[i] != "+") and (r[i] != "-") and (r[i] != "*") and (r[i] != "/")) { - chisla.push_back(stoi(r[i])); - } else { - znak = r[i]; - } - } - if (!chisla.empty()) - rez = chisla[0]; - else { - cout << "Error" << endl; - rez = -1; - } - cout << znak << endl; - if (!chisla.empty()) { - for (i = 1; i < chisla.size(); ++i) { - if (znak == "+") { - rez += chisla[i]; - } - if (znak == "-") { - rez -= chisla[i]; - } - if (znak == "*") { - rez *= chisla[i]; - } - if (znak == "/") { - rez /= chisla[i]; - } - } + for (i = 0; i < r.size(); ++i) { + if ((r[i] != "+") and (r[i] != "-") and (r[i] != "*") and (r[i] != "/")) { + chisla.push_back(stoi(r[i])); + } else { + znak = r[i]; } - return rez; } -} - -int CalculatePrefix(const std::string& data) { - cout << "Not Ready" << endl; - int i = 0; - int buff_int = 0; - std::string znak; - int rez = 0; - // std::string buff_str; - vector chisla; - vector r = SplitString(data); - for (int i = 0; i < r.size(); ++i) { - std::cout << i << "element: " << r[i] << '\n'; + if (!chisla.empty()) + rez = chisla[0]; + else { + cout << "Error" << endl; + rez = -1; } - for (i = 0; i < data.size(); ++i) { - if ((data[i] >= '0') && (data[i] <= '9')) { - } - for (i = 0; i < r.size(); ++i) { - if ((r[i] != "+") and (r[i] != "-") and (r[i] != "*") and (r[i] != "/")) { - chisla.push_back(stoi(r[i])); - } else { - znak = r[i]; + if (!chisla.empty()) { + for (i = 1; i < chisla.size(); ++i) { + if (znak == "+") { + rez += chisla[i]; } - } - if (!chisla.empty()) - rez = chisla[0]; - else { - cout << "Error" << endl; - rez = -1; - } - cout << znak << endl; - if (!chisla.empty()) { - for (i = 1; i < chisla.size(); ++i) { - if (znak == "+") { - rez += chisla[i]; - } - if (znak == "-") { - rez -= chisla[i]; - } - if (znak == "*") { - rez *= chisla[i]; - } - if (znak == "/") { - rez /= chisla[i]; - } + if (znak == "-") { + rez -= chisla[i]; + } + if (znak == "*") { + rez *= chisla[i]; + } + if (znak == "/") { + rez /= chisla[i]; } } - return rez; } + return rez; } diff --git a/homework_01/task_02/src/utils.hpp b/homework_01/task_02/src/utils.hpp index 711028c..d185005 100644 --- a/homework_01/task_02/src/utils.hpp +++ b/homework_01/task_02/src/utils.hpp @@ -6,7 +6,3 @@ int Calculate(const std::string& data); std::vector SplitString(const std::string& data); -bool IsInt_bad_version(const std::string& str); -bool IsInt(const std::string& str); -bool IsDouble(const std::string& str); -std::string Parce(const std::string& input); \ No newline at end of file From 19cd22960ba8dca5b146fcef93ead419c7fbe2bb Mon Sep 17 00:00:00 2001 From: Artem Date: Mon, 5 Dec 2022 18:02:27 +0000 Subject: [PATCH 5/5] update tak02 --- homework_01/task_02/src/main.cpp | 7 ++++++- homework_01/task_02/src/utils.cpp | 24 +++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/homework_01/task_02/src/main.cpp b/homework_01/task_02/src/main.cpp index 548ee13..f160237 100644 --- a/homework_01/task_02/src/main.cpp +++ b/homework_01/task_02/src/main.cpp @@ -5,4 +5,9 @@ #include #include using namespace std; -int main() { return 0; } +int main() { + cout << "Itog:" << endl; + cout << Calculate("8/0") << endl; + cout << Calculate("8 / 0") << endl; + return 0; +} diff --git a/homework_01/task_02/src/utils.cpp b/homework_01/task_02/src/utils.cpp index c819e1a..cbe7b88 100644 --- a/homework_01/task_02/src/utils.cpp +++ b/homework_01/task_02/src/utils.cpp @@ -31,12 +31,12 @@ std::vector SplitString(const std::string& data) { if (buff != "") { v.push_back(buff); buff = ""; - if ((data[i] == '+') or (data[i] == '-') or (data[i] == '*') or - (data[i] == '/')) { - buff += data[i]; - v.push_back(buff); - buff = ""; - } + } + if ((data[i] == '+') or (data[i] == '-') or (data[i] == '*') or + (data[i] == '/')) { + buff += data[i]; + v.push_back(buff); + buff = ""; } } } else { @@ -54,18 +54,19 @@ std::vector SplitString(const std::string& data) { int Calculate(const std::string& data) { int i = 0; int buff_int = 0; - std::string znak; + std::string znak = ""; int rez = 0; vector chisla; vector r = SplitString(data); for (i = 0; i < r.size(); ++i) { + cout << r[i] << endl; if ((r[i] != "+") and (r[i] != "-") and (r[i] != "*") and (r[i] != "/")) { chisla.push_back(stoi(r[i])); } else { znak = r[i]; } } - if (!chisla.empty()) + if (!chisla.empty() and !znak.empty()) rez = chisla[0]; else { cout << "Error" << endl; @@ -83,7 +84,12 @@ int Calculate(const std::string& data) { rez *= chisla[i]; } if (znak == "/") { - rez /= chisla[i]; + if (chisla[i] != 0) + rez /= chisla[i]; + else { + cout << "Delit na Nol nelzya!" << endl; + rez = -1; + } } } }