From 05c6a0a855b728630879f9cf82eface80fea737b Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 22 Oct 2022 08:16:47 +0000 Subject: [PATCH 1/3] 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/3] 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/3] 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; -} -} - - - -