Skip to content

Feature/solve first homework - #16

Open
half-crazyyy wants to merge 7 commits into
DafeMipt212:mainfrom
half-crazyyy:feature/solve_first_homework
Open

Feature/solve first homework#16
half-crazyyy wants to merge 7 commits into
DafeMipt212:mainfrom
half-crazyyy:feature/solve_first_homework

Conversation

@half-crazyyy

Copy link
Copy Markdown

No description provided.

Comment thread homework_01/task_01/src/utils.cpp Outdated
std::vector<std::string> SplitString(const std::string& data) {
return {};
}
vector <string> SplitString(string& s){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Данной функции следует принимать const string& s по очень важной причине: убирая модификатор const вы теряете возможность передавать в функцию с-строки типа const char* (а именно такой тип у литералов вроде "Hello World")

Comment thread homework_01/task_01/src/utils.cpp Outdated
}
vector <string> SplitString(string& s){
s += " ";
string CurrentString = "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

По кодстайлу имя должно быть current_string (кстати, не очень удачное имя; лучше word, token, ну или даже sub_string)

Comment thread homework_01/task_01/src/utils.cpp Outdated
vector <string> SplitString(string& s){
s += " ";
string CurrentString = "";
char* ptr = &(s[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.

Тут указатель совсем не нужен. Лучше обращаться к символу в строке просто по его номеру s[i]

Comment thread homework_01/task_01/src/utils.cpp Outdated
s += " ";
string CurrentString = "";
char* ptr = &(s[0]);
vector <string> data;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Плохое имя. Что угодно можно назвать data. Я бы назвал эту переменную просто res

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.

я бы не экономил символы и вообще написал result, так сразу понятно, а с res можно спутать с русрсом, что вряд ли но может сбить в других местах

Comment thread homework_01/task_01/src/utils.cpp Outdated
++ptr;
}
for(int i = 0; i < data.size(); ++i){
cout << data[i] << endl;}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Слова в cout вы, наверно, для отладки выводили? Отладочный код из финальной версии надо убирать (особенно если он производит побочные действия вроде засорения окна консоли)

Comment thread homework_01/task_01/src/utils.cpp Outdated
}
else {
CurrentString += *ptr;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Аккуратнее с отступами

char* ptr = &(s[0]);
vector <string> data;

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

#include <stack>
#include <iostream>
#include <vector>
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 не использовать)

Comment thread homework_01/task_02/src/utils.cpp Outdated
data.push_back(CurrentString);
CurrentString = "";
++ptr;
}

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 <stack>
#include <iostream>
#include <vector>
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; да и других пространств имен, в исключении случая когда они используются внутри функции

Comment thread homework_01/task_01/src/utils.cpp Outdated
s += " ";
string CurrentString = "";
char* ptr = &(s[0]);
vector <string> data;

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.

я бы не экономил символы и вообще написал result, так сразу понятно, а с res можно спутать с русрсом, что вряд ли но может сбить в других местах

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants