Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dec7e67
add solution: add condition task
kaigorodovMM Nov 28, 2025
06c5afb
add solution: add rms task
kaigorodovMM Nov 28, 2025
a3f7150
add solution: add print_bits task
kaigorodovMM Nov 28, 2025
9d3ad6a
add solution: add check_flags task
kaigorodovMM Nov 28, 2025
717cd0f
add solution: add length_lit task
kaigorodovMM Nov 28, 2025
0a4e403
Merge branch 'main' of github.com:psds-cpp/psds-cpp-2025
kaigorodovMM Dec 9, 2025
c0bd5f4
add solution: add swap_ptr task
kaigorodovMM Dec 9, 2025
4eefb34
add solution: add func_array task
kaigorodovMM Dec 9, 2025
cb16913
add solution: add longest task
kaigorodovMM Dec 9, 2025
137ed90
add solution: add last_of_us task
kaigorodovMM Dec 9, 2025
6736536
add solution: add pretty_array task
kaigorodovMM Dec 9, 2025
6b59a4a
Merge branch 'main' of github.com:psds-cpp/psds-cpp-2025
kaigorodovMM Dec 18, 2025
8d44aa3
add solution: add data_stats task
kaigorodovMM Dec 18, 2025
a1d5e06
add solution: add unique task
kaigorodovMM Dec 18, 2025
4f34559
add solution: add range task
kaigorodovMM Dec 18, 2025
7d78143
add solution: add minmax task
kaigorodovMM Dec 18, 2025
26cca11
edit unique task
kaigorodovMM Dec 18, 2025
71022cd
edit data_stats task
kaigorodovMM Dec 18, 2025
0a48c21
edit CMakeLists.txt
kaigorodovMM Dec 18, 2025
3b7f11e
edit CMakeLists.txt
kaigorodovMM Dec 18, 2025
d3c7972
add solution: add find_all task
kaigorodovMM Dec 19, 2025
d113d10
add solution: add os_overload task
kaigorodovMM Dec 19, 2025
f138cee
add solution: add easy_compare task
kaigorodovMM Dec 19, 2025
f971b6d
add solution: add filter task
kaigorodovMM Dec 19, 2025
4c2320e
Merge branch 'main' of
kaigorodovMM Dec 26, 2025
0a562d0
add solution: add stack task
kaigorodovMM Dec 26, 2025
53346cf
add solution: add queue task
kaigorodovMM Dec 26, 2025
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
4 changes: 3 additions & 1 deletion 01_week/tasks/addition/addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@


int64_t Addition(int a, int b) {
throw std::runtime_error{"Not implemented"};
int64_t c = static_cast<int64_t>(a);
int64_t d = static_cast<int64_t>(b);
return c + d;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Создавать переменные с непонятными именами излишне, в данном случае эффективнее и читабельнее написать выражение непосредственно в строке return. Причем будет достаточно одного каста, поскольку второй аргумент будет приведен неявно.

}
64 changes: 56 additions & 8 deletions 01_week/tasks/check_flags/check_flags.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
#include <cstdint>
#include <stdexcept>
#include <iostream>


enum class CheckFlags : uint8_t {
NONE = 0,
TIME = (1 << 0),
DATE = (1 << 1),
USER = (1 << 2),
CERT = (1 << 3),
KEYS = (1 << 4),
DEST = (1 << 5),
NONE = 0, //0
TIME = (1 << 0), //1
DATE = (1 << 1), //2
USER = (1 << 2), //4
CERT = (1 << 3), //8
KEYS = (1 << 4), //16
DEST = (1 << 5), //32
ALL = TIME | DATE | USER | CERT | KEYS | DEST
};

void PrintCheckFlags(CheckFlags flags) {
throw std::runtime_error{"Not implemented"};
if (flags <= CheckFlags::ALL && flags >= CheckFlags::NONE){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Тут скорее хотелось бы вынести короткую ветвь отдельно, чтобы избежать лишней вложенности для всех дальнейших действий. То есть если флаг больше ALL, то печатаем пустые скобки и возвращаемся из функции. тогда для всех остальных действий не нужна была бы вложенность в первый if и так понятнее, поскольку, чтобы понять чем закончится дело если у нас всё-таки больше ALL трудно, надо пролистать много строк.

std::cout << "[";
bool prev_print = 0;
if (static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::TIME)){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

не хватает пробала перед {

if (prev_print == 1){
std::cout << ",";
}
std::cout << "TIME";
prev_print = 1;
}
if (static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::DATE)){
if (prev_print == 1){
std::cout << ",";
}
std::cout << "DATE";
prev_print = 1;
}
if (static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::USER)){
if (prev_print == 1){
std::cout << ",";
}
std::cout << "USER";
prev_print = 1;
}
if (static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::CERT)){
if (prev_print == 1){
std::cout << ",";
}
std::cout << "CERT";
prev_print = 1;
}
if (static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::KEYS)){
if (prev_print == 1){
std::cout << ",";
}
std::cout << "KEYS";
prev_print = 1;
}
if (static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::DEST)){
if (prev_print == 1){
std::cout << ",";
}
std::cout << "DEST";
prev_print = 1;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Много дублирования, можно было вынести общие части придумав другую логику

std::cout << "]";
}

}
41 changes: 41 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
double operator""_cm_to_m(long double x) {
return x / 100.0;
}
double operator""_m_to_cm(long double x) {
return x* 100.0;
}

double operator""_in_to_ft(long double x) {
return x / 12.0;
}
double operator""_ft_to_in(long double x) {
return x * 12.0;
}

double operator""_m_to_ft(long double x) {
return x / 0.3048;
}
double operator""_ft_to_m(long double x) {
return x * 0.3048;
}

double operator""_cm_to_ft(long double x) {
return x / 30.48;
}
double operator""_ft_to_cm(long double x) {
return x * 30.48;
}

double operator""_cm_to_in(long double x) {
return x / 30.48 * 12.0;
}

double operator""_m_to_in(long double x) {
return x* 100.0 / 30.48 * 12.0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

нет пробела перед *

}
double operator""_in_to_cm(long double x) {
return x / 12.0 * 30.48;
}
double operator""_in_to_m(long double x) {
return x / 12.0 * 30.48 / 100;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Не принято использовать magic value в коде (кроме понятной 100 и других подобных). В данном случае лучше объявить константы для 12, 30.48, например, чтобы затем использовать данные константы с понятными именами

12 changes: 11 additions & 1 deletion 01_week/tasks/print_bits/print_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include <cstddef>
#include <stdexcept>
#include <iostream>


void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
if (bytes > 0 && bytes <= 8){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

нет пробела перед {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

лишняя вложенность, лучше сделать котороткую ветвь на выход из функции

std::cout << "0b";
for(size_t i = 0; i < bytes * 8; ++i) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

нет пробела после for

std::cout << ((value >> (bytes * 8 - i - 1)) & 1);
if (i != (bytes * 8 - 1) && (i % 4 == 3) && i != 0)
std::cout << '\'';
else if (i == bytes * 8 - 1)
std::cout << '\n';
}
}
}
12 changes: 10 additions & 2 deletions 01_week/tasks/rms/rms.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include <cstdef>
#include <cstddef>
#include <stdexcept>
#include <cmath>


double CalculateRMS(double values[], size_t size) {
throw std::runtime_error{"Not implemented"};
if (size == 0 || values == nullptr){
return 0.0;
}
double rms = 0;
for (size_t i = 0; i < size; ++i){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

пробелы перед {

rms += values[i] * values[i];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

по факту это сумма квадратов нежели rms, поскольку в конце мы возвращаем не rms, а выражение, которое вычисляет rms, не совсем корректное название

}
return sqrt(rms/size);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • использовать лучше std::sqrt
  • нет пробелов вокруг оператора /

}
13 changes: 11 additions & 2 deletions 02_week/tasks/func_array/func_array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#include <stdexcept>


double ApplyOperations(double a, double b /* other arguments */) {
throw std::runtime_error{"Not implemented"};
double ApplyOperations(double a, double b, double (**arr_func)(double, double), size_t size) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

для наглядности лучше всё такие в сигнатуре указывать массив указателей, чем указатель на указатель, это будет более наглядно

double result = 0;
if (size == 0 or arr_func == nullptr){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

пробел перед {

return 0.0;
}
for (size_t i = 0; i < size; ++i){
if (arr_func[i] != nullptr){
result += arr_func[i](a, b);
}
}
return result;
}
15 changes: 13 additions & 2 deletions 02_week/tasks/last_of_us/last_of_us.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#include <stdexcept>


/* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) {
throw std::runtime_error{"Not implemented"};
int* FindLastElement(const int* begin, const int* end, bool (*predicate) (int)) {
if (begin == nullptr or end == nullptr or begin >= end){
return const_cast<int*>(end);
}
int* result = const_cast<int*>(end);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

В данном случае это некорректное решение задачи приводящие к UB при передачи действительно константного объекта, нельзя снимать константность, если в исходном варианте это был указатель на константу. Корректно было сделать две версии функции, одна принимает и возвращает указатели на константу, другая просто указатели. И вот в таком случае, чтобы избежать дублирования в версии неконстантной можно было вызвать константную и с результата снять константность. это было бы корректно, так как исходная версия функция была не константная.

int* p = const_cast<int*>(begin);
while (p < end){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

пробел перед {

if(predicate(*p)){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

пробелы после if и перед {

result = p;
}
p++;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

зачем постфиксный инкремент, должен быть префиксный

}
return result;
}
28 changes: 26 additions & 2 deletions 02_week/tasks/longest/longest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
#include <stdexcept>


/* return_type */ FindLongestSubsequence(/* ptr_type */ begin, /* ptr_type */ end, /* type */ count) {
throw std::runtime_error{"Not implemented"};
char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) {
count = 0;
if ((begin >= end) or (begin == nullptr) or (end == nullptr)){
Copy link
Contributor Author

@18thday 18thday Jan 12, 2026

Choose a reason for hiding this comment

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

or - словестное операторы в C++ не принято писать, обычно по стайл гайдам ||

return nullptr;
}
char* long_begin = const_cast<char*>(begin);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ситуация аналогична задаче last_of_us - это некорректное решение, так как содержит UB

//char long_char = *begin;
size_t len = 0;
char* char0 = const_cast<char*>(begin);
while (begin <= end){
if(*char0 == *begin){
len++;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

должен быть префиксный инкремент

}
else{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это длинная ветвь с еще одним уровнем вложенности, лучше первый if дополнить сдвигом указателя и continue и избавится от else вовсе

if (len > count){
count = len;
//long_char = char0;
long_begin = const_cast<char*>(char0);
}
char0 = const_cast<char*>(begin);
len = 1;
}

begin++;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

должен быть префиксный инкремент

}
return long_begin;
}
48 changes: 46 additions & 2 deletions 02_week/tasks/pretty_array/pretty_array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
#include <stdexcept>
#include <iostream>


void PrintArray(/* write arguments here */) {
throw std::runtime_error{"Not implemented"};

void PrintArray(const int* begin, const int* end, size_t ogr = 0) {
/*if (begin == nullptr or end == nullptr){
return;
}*/

size_t i_ogr = 1;
std::cout <<"[";

if (end >= begin){
int* p = const_cast<int*>(begin);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Это некорректно, снова UB, мы не должны снимать константность, так как не меняем значение под указателем. Нужно работать с константными указателями, просто выводим значения на экран

while (p < end){
std::cout << *p;
if (p + 1 != end){
std::cout <<", ";
if (ogr != 0 and i_ogr == ogr){
std::cout << "..." << std::endl << " ";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

не нужно на каждом цикле сбрасывать буфер, следует заменить std::endl на \n

i_ogr = 0;
}
}

p++;
i_ogr++;
}
}
else{
int* p = const_cast<int*>(end);
p--;
while (p >= begin){
std::cout << *p;
if (p != begin){
std::cout <<", ";
if (ogr != 0 and i_ogr == ogr){
std::cout << "..." << std::endl << " ";
i_ogr = 0;
}
}

p--;
i_ogr++;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

}


std::cout << "]" << std::endl;
}
19 changes: 16 additions & 3 deletions 02_week/tasks/swap_ptr/swap_ptr.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#include <stdexcept>


void SwapPtr(/* write arguments here */) {
throw std::runtime_error{"Not implemented"};
}
void SwapPtr(int*& ptr1, int*& ptr2) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

обыычно принято называть lhs, rhs (left/right hand side) что говорит левый и правый аргумент и короче

int* ptr0 = ptr1;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

вместо ptr0, комфортнее было бы temp, что явно говорит, что это временная переменная и нет необходимости искать глазами цифру среди ptr

ptr1 = ptr2;
ptr2 = ptr0;
}
void SwapPtr(const int*& ptr1, const int*& ptr2) {
const int* ptr0 = ptr1;
ptr1 = ptr2;
ptr2 = ptr0;
}
void SwapPtr(int**& ptr1, int**& ptr2) {
int** ptr0 = ptr1;
ptr1 = ptr2;
ptr2 = ptr0;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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


42 changes: 40 additions & 2 deletions 03_week/tasks/data_stats/data_stats.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
#include <cmath>
#include <stdexcept>
#include <vector>


struct DataStats {
double avg = 0.0;
double sd = 0.0;
};

/* return_type */ CalculateDataStats(/* args */) {
throw std::runtime_error{"Not implemented"};
DataStats CalculateDataStats(std::vector<int>& vect) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

обычно называют values

int n = 0;

DataStats rezult = {0, 0};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

result - не нужно русифицировать английский

if (vect.begin() == vect.end()){
return rezult;
}
for (auto it = vect.begin(); it != vect.end(); ++it) {
++n;
rezult.avg += *it;
}
rezult.avg /= n;
for (auto it = vect.begin(); it != vect.end(); ++it) {
rezult.sd += pow((*it - rezult.avg), 2);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Два цикла, есть возможность считать это в одном цикле, при большом количестве элементов два прохода может быть заметно накладнее одного

rezult.sd /= n;
rezult.sd = sqrt(rezult.sd);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

std::sqrt

return rezult;
}

DataStats CalculateDataStats(const std::vector<int>& vect) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. полное дублирование кода,
  2. поскольку мы не меняем исходные данные, должна быть только константная версия аргумента

int n = 0;

DataStats rezult = {0, 0};
if (vect.begin() == vect.end()){
return rezult;
}
for (auto it = vect.begin(); it != vect.end(); ++it) {
++n;
rezult.avg += *it;
}
rezult.avg /= n;
for (auto it = vect.begin(); it != vect.end(); ++it) {
rezult.sd += pow((*it - rezult.avg), 2);
}
rezult.sd /= n;
rezult.sd = sqrt(rezult.sd);
return rezult;
}
Loading
Loading