Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions homework_01/task_01/src/utils.cpp
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

считается плохим тоном использовать using namespace std; да и других пространств имен, в исключении случая когда они используются внутри функции


vector <string> SplitString(const string& s){

string Current_String = "";
const char* ptr = &(s[0]);
vector <string> result;

while(*ptr != '\0'){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (size_t i = 0; i < s.size(); i++) {

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;
}
2 changes: 1 addition & 1 deletion homework_01/task_01/src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#include <string_view>
#include <vector>

std::vector<std::string> SplitString(const std::string& data);
std::vector<std::string> SplitString(std::string& s);
37 changes: 35 additions & 2 deletions homework_01/task_02/src/utils.cpp
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отделите пустой строкой #include <vector> от using namespace std; (а ещё лучше вообще using namespace std не использовать)


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;
}
2 changes: 1 addition & 1 deletion homework_01/task_02/src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#include <string_view>
#include <vector>

int Calculate(const std::string& data);
int Calculate(std::string& data);