-
Notifications
You must be signed in to change notification settings - Fork 21
Task 01 02 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Task 01 02 #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| #include <iostream> | ||
|
|
||
| #include <utils.hpp> | ||
|
|
||
| int main() { | ||
| for (const auto& word : SplitString("asdas das das fgag (adasd 1fas)")) { | ||
| std::cout << word << "\n"; | ||
| std::string line; | ||
| line = "a\na\ta a"; | ||
| for (const auto& word : SplitString(line)) { | ||
| std::cout << word << '\n'; | ||
| } | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,44 @@ | ||
| #include "utils.hpp" | ||
|
|
||
| #include <stack> | ||
| #include <string.h> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это сишны инклуд, лучше использовать цппшный (cstring) |
||
|
|
||
| #include <iostream> | ||
| #include <stack> | ||
| #include <string> | ||
| #include <vector> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вставь пустую строчку, так будет лучше выглядеть, и после using namespace |
||
| using namespace std; | ||
| std::vector<std::string> SplitString(const std::string& data) { | ||
| return {}; | ||
| std::vector<std::string> v; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. плохое имя переменной |
||
| std::string buff = ""; | ||
| bool flag = false; //скобки закрыты (или их нет) | ||
| // cout << size(data) << endl; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. убери отладку |
||
| for (int i = 0; i < size(data); ++i) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше использовать data.size() |
||
| if (data[i] == '(') { | ||
| flag = true; //скобки открыты | ||
| } else if (data[i] == ')') { | ||
| flag = false; //скобки закрыты | ||
| } | ||
| if (((data[i] != ' ') and (data[i] != '\t')) or (flag == true)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| #include <iostream> | ||
| #include <string.h> | ||
|
|
||
| #include <iostream> | ||
| #include <regex> | ||
| #include <stack> | ||
| #include <utils.hpp> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вставь пустую строчку перед |
||
|
|
||
| using namespace std; | ||
| int main() { | ||
| std::string data; | ||
| std::getline(std::cin, data); | ||
| std::cout << Calculate(data); | ||
| cout << "Itog:" << endl; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше не использовать транслит в коде |
||
| cout << Calculate("8/0") << endl; | ||
| cout << Calculate("8 / 0") << endl; | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,97 @@ | ||
| #include "utils.hpp" | ||
|
|
||
| #include <string.h> | ||
|
|
||
| #include <iostream> | ||
| #include <regex> | ||
| #include <stack> | ||
| #include <string> | ||
| #include <vector> | ||
| using namespace std; | ||
|
|
||
| std::vector<std::string> SplitString(const std::string& data) { | ||
| std::vector<std::string> v; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. плохое название переменной |
||
| 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') and (data[i] != '+') and | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в плюсовом коде используются |
||
| (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 (data[i] == '+') or | ||
| (data[i] == '-') or (data[i] == '*') or (data[i] == '/') or | ||
| (i + 1 >= size(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 = ""; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
| } else { | ||
| if (i + 1 >= size(data)) { | ||
| if (buff != "") { | ||
| v.push_back(buff); | ||
| buff = ""; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return v; | ||
| } | ||
|
|
||
| int Calculate(const std::string& data) { | ||
| return 0; | ||
| int i = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. если это индекс для for то обяви его в for |
||
| int buff_int = 0; | ||
| std::string znak = ""; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не используй транслит |
||
| int rez = 0; | ||
| vector<int> chisla; | ||
| vector<string> r = SplitString(data); | ||
| for (i = 0; i < r.size(); ++i) { | ||
| cout << r[i] << endl; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Прошу убрать отладочный код |
||
| if ((r[i] != "+") and (r[i] != "-") and (r[i] != "*") and (r[i] != "/")) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вы в коде несколько раз проверяете, является ли символ арифметическим оператором, а это длинный |
||
| chisla.push_back(stoi(r[i])); | ||
| } else { | ||
| znak = r[i]; | ||
| } | ||
| } | ||
| if (!chisla.empty() and !znak.empty()) | ||
| rez = chisla[0]; | ||
| else { | ||
| cout << "Error" << endl; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут можно просто кинуть исключение, например runtime_error |
||
| rez = -1; | ||
| } | ||
| 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 == "/") { | ||
| if (chisla[i] != 0) | ||
| rez /= chisla[i]; | ||
| else { | ||
| cout << "Delit na Nol nelzya!" << endl; | ||
| rez = -1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return rez; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ | |
| #include <vector> | ||
|
|
||
| int Calculate(const std::string& data); | ||
| std::vector<std::string> SplitString(const std::string& data); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. эта функция используется в реализации, ее лучше не вытаскивать в hpp, и оставить в cpp |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
оставь пустую строчку, так приянто разделять библиотечные инклуды и инклуды из программы