-
Notifications
You must be signed in to change notification settings - Fork 21
homework #12
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?
homework #12
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,7 +1,51 @@ | ||
| #include "utils.hpp" | ||
|
|
||
| #include <stack> | ||
| #include <vector> | ||
| #include <string> | ||
|
|
||
| std::vector<std::string> SplitString(const std::string& data) { | ||
| return {}; | ||
| } | ||
| std::vector<std::string> SplitString(const std::string& data, const char& del) { | ||
| std::vector <std::string> allstrings; | ||
| std::string onestring = ""; | ||
| std::string brackets = { '(', ')' }; | ||
|
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. интересное решение, yj я бы добавил const |
||
| bool in_brackets = 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 (const char& symbol : data) | ||
| { | ||
| if (symbol != del && symbol != brackets[in_brackets] && symbol != '\t') | ||
| onestring.push_back(symbol); | ||
| else | ||
| { | ||
| if (in_brackets) | ||
| { | ||
| if (symbol == brackets[in_brackets]) | ||
| { | ||
| onestring.push_back(symbol); | ||
| allstrings.push_back(onestring); | ||
| onestring = ""; | ||
|
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. onestring.clear() смотрится лучше |
||
| in_brackets = 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. false |
||
| } | ||
| else | ||
| onestring.push_back(symbol); | ||
| } | ||
| else | ||
| { | ||
| if (symbol == brackets[in_brackets]) | ||
| { | ||
| if (onestring != "") | ||
|
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. !onestring.empty() так чаще принято писать |
||
| allstrings.push_back(onestring); | ||
| onestring = ""; | ||
| onestring.push_back(symbol); | ||
| in_brackets = 1; | ||
| } | ||
| else | ||
| { | ||
| if (onestring != "") | ||
| allstrings.push_back(onestring); | ||
| onestring = ""; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (onestring != "") | ||
| allstrings.push_back(onestring); | ||
| return allstrings; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,36 @@ | ||
| #include "utils.hpp" | ||
|
|
||
| #include <stack> | ||
|
|
||
| int Calculate(const std::string& data) { | ||
| return 0; | ||
| } | ||
| int Calculate(const std::string& data) | ||
| { | ||
| 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. это индекс, так что лучше использовать size_t |
||
| int a = 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. полохое название переменной |
||
| while (isdigit(data[i])&& i < data.length()) | ||
|
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. пробел пропущен |
||
| { | ||
| a *= 10; | ||
| a += int(data[i]) - 48; | ||
| i++; | ||
| } | ||
| std::string operation = ""; | ||
| while (!isdigit(data[i]) && i < data.length()) | ||
| { | ||
| operation += data[i]; | ||
| i++; | ||
| } | ||
| int b = 0; | ||
| while (isdigit(data[i]) && i < data.length()) | ||
| { | ||
| b *= 10; | ||
| b += int(data[i]) - 48; | ||
| i++; | ||
| } | ||
| if (operation == "+") | ||
|
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. тут лучше бы смотрелся switch |
||
| return a + b; | ||
| else if (operation == "-") | ||
| return a - b; | ||
| else if (operation == "*") | ||
| return a * b; | ||
| else if (operation == "/") | ||
| return a / b; | ||
| else | ||
| return 36606; | ||
|
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. а что за магическое число? что оно значит? |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ | |
| #include <vector> | ||
|
|
||
| int Calculate(const std::string& data); | ||
|
|
||
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.
я бы назвал one_string, но как-то название тоже не очень, возможно word или что-то подобное лучше будет