-
Notifications
You must be signed in to change notification settings - Fork 21
Feature/solve first homework #16
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?
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,37 @@ | ||
| #include "utils.hpp" | ||
|
|
||
| #include <stack> | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| std::vector<std::string> SplitString(const std::string& data) { | ||
| return {}; | ||
| } | ||
| using namespace std; | ||
|
|
||
| vector <string> SplitString(const string& s){ | ||
|
|
||
| string Current_String = ""; | ||
| const char* ptr = &(s[0]); | ||
| vector <string> result; | ||
|
|
||
| while(*ptr != '\0'){ | ||
|
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 (*ptr == '(') { | ||
| while((*ptr != ')') && (*ptr != '\0')){ | ||
| Current_String += *ptr; | ||
| ++ptr; | ||
| } | ||
| Current_String += *ptr; | ||
| ++ptr; | ||
| result.push_back(Current_String); | ||
| Current_String = ""; | ||
| } | ||
| if ((*ptr == ' ') || (*ptr == '\t')) { | ||
| if (Current_String != "") result.push_back(Current_String); | ||
| Current_String = ""; | ||
| } | ||
| else { | ||
| Current_String += *ptr; | ||
| } | ||
| ++ptr; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,40 @@ | ||
| #include "utils.hpp" | ||
|
|
||
| #include <stack> | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| int Calculate(const std::string& data) { | ||
| return 0; | ||
| using namespace std; | ||
|
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 Calculate(const string& str) { | ||
|
|
||
| string CurrentString = ""; | ||
| const char* ptr = &(str[0]); | ||
| vector <string> data; | ||
|
|
||
| while(*ptr != '\0'){ | ||
| if ((*ptr == '+') ||(*ptr == '-')||(*ptr == '*')||(*ptr == '/')) { | ||
| if (CurrentString != ""){ | ||
| data.push_back(CurrentString); | ||
| CurrentString = ""; | ||
| } | ||
| CurrentString += *ptr; | ||
| data.push_back(CurrentString); | ||
| CurrentString = ""; | ||
| ++ptr; | ||
| } | ||
|
|
||
| CurrentString += *ptr; | ||
| ++ptr; | ||
| } | ||
| data.push_back(CurrentString); | ||
|
|
||
| int a = stoi(data[0]); | ||
| int b = stoi(data[2]); | ||
|
|
||
| if (data[1] == "+") {return a + b;} | ||
| else if (data[1] == "-") {return a - b;} | ||
| else if (data[1] == "*") {return a * b;} | ||
| else if (data[1] == "/") {return a / b;} | ||
| else return 0; | ||
| } | ||
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.
считается плохим тоном использовать using namespace std; да и других пространств имен, в исключении случая когда они используются внутри функции