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
6 changes: 4 additions & 2 deletions homework_01/task_01/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include <utils.hpp>

int main() {
for (const auto& word : SplitString("asdas das das fgag (adasd 1fas)")) {
std::cout << word << "\n";
for (const auto& word : SplitString(
"asdas das das fgag (adasd 1fas)")
) {
std::cout << word<< "\n";
}
return 0;
}
52 changes: 48 additions & 4 deletions homework_01/task_01/src/utils.cpp
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 = "";

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.

я бы назвал one_string, но как-то название тоже не очень, возможно word или что-то подобное лучше будет

std::string brackets = { '(', ')' };

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.

интересное решение, yj я бы добавил const

bool in_brackets = 0;

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.

bool in_brackets = true;
присвоение bool'у нуля смотрится так себе

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 = "";

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.

onestring.clear() смотрится лучше

in_brackets = 0;

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.

false

}
else
onestring.push_back(symbol);
}
else
{
if (symbol == brackets[in_brackets])
{
if (onestring != "")

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.

!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;
}
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(const std::string& data, const char& del = ' ');
39 changes: 34 additions & 5 deletions homework_01/task_02/src/utils.cpp
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;

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.

это индекс, так что лучше использовать size_t

int a = 0;

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.

полохое название переменной
намного лучше выглядит например left_number, но кажется можно и лучше придумать

while (isdigit(data[i])&& i < data.length())

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.

пробел пропущен

{
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 == "+")

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.

тут лучше бы смотрелся 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;

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.

а что за магическое число? что оно значит?

}
1 change: 1 addition & 0 deletions homework_01/task_02/src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#include <vector>

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