Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
786c587
add solution: addition, rms, print_bits tasks
Nov 22, 2025
e47e779
Merge branch 'main' into week_01
Nov 23, 2025
2be84bb
add (solution): add check_flags task
Nov 23, 2025
73ae725
add (solution) add quadratic tast
Nov 23, 2025
3c312a5
add solution: add length_lit task
Nov 24, 2025
97ebf04
Merge remote-tracking branch 'origin/main' into week_01
Nov 25, 2025
5eb2252
Merge branch 'main' into week_01
Dec 2, 2025
b53ca2a
add [solution]: add task swap_ptr
Dec 3, 2025
3e5a80a
add [solution]: add task func_array
Dec 3, 2025
9159eeb
add [solution]: add task longest
Dec 3, 2025
b20c4ff
Merge pull request #1 from WhoAmI1909/week_01
WhoAmI1909 Dec 6, 2025
097fc7d
Merge branch 'main' into week_02
Dec 6, 2025
9f39dfa
add [solution]: add task last_of_us
Dec 6, 2025
4f48105
add [solution]: add task little_big
Dec 6, 2025
b6f99dc
add [solution]: add task pretty_array
Dec 7, 2025
78363af
Merge branch 'psds-cpp:main' into main
WhoAmI1909 Dec 10, 2025
e8920e7
add solution: add task [data_stats]
Dec 14, 2025
56befd7
add solution: add task [unique]
Dec 14, 2025
27abbaa
add solution: add task [range]
Dec 14, 2025
a5f6e06
add solution: add task [minmax]
Dec 14, 2025
dca960a
add solution: add task [find_all]
Dec 14, 2025
81a216b
add solution: add task [os_overload]
Dec 15, 2025
99c2021
add solution: add task [easy_compare]
Dec 16, 2025
0ecaae7
add solution: add task [filter]
Dec 16, 2025
07c7889
Merge branch 'psds-cpp:main' into main
WhoAmI1909 Dec 18, 2025
8ecb3cb
Merge branch 'main' into week_03
Dec 18, 2025
7658216
Merge pull request #2 from WhoAmI1909/week_02
WhoAmI1909 Dec 18, 2025
17ee479
Merge branch 'main' into week_03
Dec 18, 2025
5fda3fb
Для тестов без 4 недели
Dec 18, 2025
bd5dc5a
Дополнены данные для конструктора по умолчанию: Date: task week_03: e…
Dec 18, 2025
c9f0966
Merge branch 'psds-cpp:main' into main
WhoAmI1909 Dec 19, 2025
6f192e0
Merge remote-tracking branch 'origin/main' into week_03
Dec 19, 2025
bddfbd5
Merge branch 'psds-cpp:main' into main
WhoAmI1909 Dec 21, 2025
34aec08
Merge remote-tracking branch 'origin/main' into week_03
Dec 21, 2025
77b1c24
add solution add task [stack]
Dec 21, 2025
45c2b50
Merge pull request #3 from WhoAmI1909/week_03
WhoAmI1909 Dec 21, 2025
159ee20
Merge branch 'psds-cpp:main' into main
WhoAmI1909 Dec 22, 2025
956c669
Merge branch 'psds-cpp:main' into main
WhoAmI1909 Jan 11, 2026
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
2 changes: 1 addition & 1 deletion 01_week/tasks/addition/addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


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

Choose a reason for hiding this comment

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

Лишний каст, второй операнд не следует приводить явно, так как он бы преобразовался с помощью неявного каста. Принято использовать такую возможность и не писать явный каст самостоятельно второй раз

}
38 changes: 37 additions & 1 deletion 01_week/tasks/check_flags/check_flags.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cstdint>
#include <stdexcept>
#include <iostream>


enum class CheckFlags : uint8_t {
Expand All @@ -14,5 +15,40 @@ enum class CheckFlags : uint8_t {
};

void PrintCheckFlags(CheckFlags flags) {
throw std::runtime_error{"Not implemented"};
// Значение находится в допустимом диапазоне
uint8_t value = static_cast<uint8_t>(flags);
if (value == 0) {
std::cout << "[]";
return;
}
if (value > static_cast<uint8_t>(CheckFlags::ALL)) {
return;
}
// Последнее значение
if (value == static_cast<uint8_t>(CheckFlags::ALL)) {
std::cout << "[TIME,DATE,USER,CERT,KEYS,DEST]";
return;
}

std::cout << "[";
bool first = true;

const std::pair<CheckFlags, const char*> flag_names[] = {
{CheckFlags::TIME, "TIME"},
{CheckFlags::DATE, "DATE"},
{CheckFlags::USER, "USER"},
{CheckFlags::CERT, "CERT"},
{CheckFlags::KEYS, "KEYS"},
{CheckFlags::DEST, "DEST"}
};
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 (const auto& [flag, name] : flag_names) {
if (value & static_cast<uint8_t>(flag)) {
if (!first) std::cout << ",";
std::cout << name;
first = false;
}
}

std::cout << "]";
}
55 changes: 55 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
double FT_IN_M = 1.0 / 0.3048;
double FT_IN_INCHES = 12.0;
double INCH_IN_CM = 2.54;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лучше будет вынести в безымянный или именной namespace


// Футы в другие величины
double operator""_ft_to_m(long double ft) {
return ft / FT_IN_M;
}

double operator""_ft_to_cm(long double ft) {
return ft / FT_IN_M * 100.0;
}

double operator""_ft_to_in(long double ft) {
return ft * FT_IN_INCHES;
}

// Дюймы в другие величины
double operator""_in_to_ft(long double in) {
return in / FT_IN_INCHES;
}

double operator""_in_to_cm(long double in) {
return in * INCH_IN_CM;
}

double operator""_in_to_m(long double inches) {
return inches * INCH_IN_CM / 100;
}

// См в другие величины
double operator""_cm_to_m(long double centimeters) {
return centimeters / 100;
}

double operator""_cm_to_in(long double centimeters) {
return centimeters / INCH_IN_CM;
}

double operator""_cm_to_ft(long double centimeters) {
return centimeters / (FT_IN_INCHES * INCH_IN_CM);
}

// Метры в другие величины
double operator""_m_to_ft(long double meters) {
return meters * 100 / (INCH_IN_CM * FT_IN_INCHES);
}

double operator""_m_to_in(long double meters) {
return meters * 100 / INCH_IN_CM;
}

double operator""_m_to_cm(long double meters) {
return meters * 100;
}
22 changes: 21 additions & 1 deletion 01_week/tasks/print_bits/print_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
#include <cstddef>
#include <stdexcept>
#include <iostream>


void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
using std::cout;
// Проверка корректности размера
if (bytes == 0 || bytes > 8) {
return;
}
std::cout << "0b";

// Проходим по всем битам, начиная со старшего
for (size_t pos = bytes * 8; pos > 0; --pos) {
// Получаем значение бита на текущей позиции
int bit = (value >> (pos - 1)) & 1;
std::cout << bit;

// Добавляем апостроф между байтами (после каждых 4 бит, кроме последней группы)
if ((pos - 1) > 0 && (pos - 1) % 4 == 0) {
std::cout << "'";
}
}

std::cout << "\n";
}
52 changes: 51 additions & 1 deletion 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
#include <stdexcept>
#include <iomanip>
#include <iostream>
#include <cmath>

void PrintRoot(double x) {
// Для избавления от заведомо небольших значений
if (std::abs(x) < 1e-10) {
x = 0.0;
}
std::cout << std::setprecision(6) << x;
}

void SolveQuadratic(int a, int b, int c) {
throw std::runtime_error{"Not implemented"};
if(a == 0 && b == 0 && c == 0) {
std::cout << "infinite solutions";
return;
}

double a_ = static_cast<double>(a);
double b_ = static_cast<double>(b);
double c_ = static_cast<double>(c);
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(a_ == 0) {
if(b_ == 0) {
// Нет решений
std::cout << "no solutions";
} else {
// Один корень линейного уравнения
PrintRoot(-c_ / b_);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лучше static_cast одной переменной, без создания

}
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лучше не плодить вложенные ветвления, короткие условия как в начале лучше, немного больше может получится проверок на 0, но это не страшно

}

double D = b_*b_ - 4*a_*c_;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

в данном случае лучше здесь сделать static_cast для одного b, а вместо 4 использовать 4.0

if (D > 0) {
double sqrt_d = std::sqrt(D);
double x1 = (-b_ - sqrt_d) / (2.0 * a_);
double x2 = (-b_ + sqrt_d) / (2.0 * a_);

// Гарантируем, что x1 < x2
if (x1 > x2) {
std::swap(x1, x2);
}
PrintRoot(x1);
std::cout << " ";
PrintRoot(x2);
}
else if (D == 0) {
double x = -b_ / (2.0 * a_);
PrintRoot(x);
}
else {
std::cout << "no solutions";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лучше начать с коротких ветвей (D < 0) с return а основной случай D > 0 вынести из под условия, чтобы не было лишней вложенность

}
}
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 square_sum = 0.0;
for(size_t i = 0; i < size; ++i) {
square_sum += values[i] * values[i];
}
return sqrt(square_sum/size);
}
16 changes: 13 additions & 3 deletions 02_week/tasks/func_array/func_array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#include <stdexcept>


double ApplyOperations(double a, double b /* other arguments */) {
throw std::runtime_error{"Not implemented"};
double ApplyOperations(double a, double b, double (*ptr[])(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.

ptr не удачно название здесь, лучше func_arr например, более соответствует действительности

double sum = 0.0;

if(size == 0 || ptr == nullptr) {
return sum;
}

for (size_t i = 0; i < size; ++i) {
if(ptr[i] == nullptr) continue;
sum += ptr[i](a, b);
}

return sum;
}
9 changes: 7 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,11 @@
#include <stdexcept>


/* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) {
throw std::runtime_error{"Not implemented"};
const int* FindLastElement(const int* begin, const int* end, bool (*predicate)(const int)) {
if((begin > end) || (begin == nullptr) || (end == nullptr)) return 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.

для указателей часто принято не использовать явное сравнение с nullptr, а использовать неявное приведение к bool !begin || !end будет короче


for(const int* ptr = end - 1; ptr >= begin; --ptr) {
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 и for ставится

if (predicate(*ptr)) {return ptr;}
}
return end;
}
43 changes: 39 additions & 4 deletions 02_week/tasks/little_big/little_big.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
#include <stdexcept>
#include <cstring>
#include <iomanip>
#include <iostream>


void PrintMemory(int /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
void PrintMemory(int value, bool reverse = false) {
unsigned char* bytes = reinterpret_cast<unsigned char*>(&value);

std::cout << "0x";

if (reverse) {
// Вывод в обратном порядке (big-endian)
for (int i = sizeof(int) - 1; i >= 0; --i) {
std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast<int>(bytes[i]);
}
} else {
// Вывод в естественном порядке (little-endian)
for (size_t i = 0; i < sizeof(int); ++i) {
std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast<int>(bytes[i]);
}
}
Copy link
Contributor Author

@18thday 18thday Jan 21, 2026

Choose a reason for hiding this comment

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

можно было попробовать избавиться от дублирование, тело одинаковое


std::cout << std::endl;
}

void PrintMemory(double /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
void PrintMemory(double value, bool reverseBytes = false) {
unsigned char* bytes = reinterpret_cast<unsigned char*>(&value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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


std::cout << "0x";

if (reverseBytes) {
// Вывод в обратном порядке (big-endian)
for (int i = sizeof(double) - 1; i >= 0; --i) {
std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast<int>(bytes[i]);
}
} else {
// Вывод в естественном порядке (little-endian)
for (size_t i = 0; i < sizeof(double); ++i) {
std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast<int>(bytes[i]);
}
}

std::cout << std::endl;
}
32 changes: 30 additions & 2 deletions 02_week/tasks/longest/longest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
#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) {
if (begin == nullptr || end == nullptr || begin >= end) {
count = 0;
return nullptr;
}

const char* longest_ptr = begin;
const char* current_ptr = begin;
size_t max_count = 1;
size_t current_count = 1;

for (const char* ptr = begin + 1; ptr < end; ++ptr) {
if (*ptr == *(ptr - 1)) {
current_count++;
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.

лучше выше написать continue, а тут избавится от вложенности лишнего else

if(current_count > max_count) {
max_count = current_count;
longest_ptr = current_ptr;
}
current_ptr = ptr;
current_count = 1;
}
}

if(current_count > max_count) {
max_count = current_count;
longest_ptr = current_ptr;
}
count = max_count;
return const_cast<char*>(longest_ptr);
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, так как мы можем принять изначально указатель на константный объект, нужно было написать две функции у одной принимаемые и возвращаемые указатели на константу, а другого простые, и вот уже из функции без константости корректно было бы вызывать константную версию и снимать константность с результата const_cast, так как была бы увереность, что объект изначально не константный

}
38 changes: 35 additions & 3 deletions 02_week/tasks/pretty_array/pretty_array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
#include <stdexcept>
#include <iostream>


void PrintArray(/* write arguments here */) {
throw std::runtime_error{"Not implemented"};
void PrintArray(const int* begin, const int* end, int constraint = 0) {
if (begin == end || begin == nullptr || end == nullptr)
{
std::cout << "[]\n";
return;
}

int count = 0;
std::cout << "[";
if(begin < end) {
for(const int* ptr = begin; ptr < end; ++ptr) {
if((count == constraint) && (constraint != 0)) {
count = 0;
std::cout << "...\n ";
}
std::cout << *ptr;
if(ptr != end - 1) { std::cout << ", "; }
++count;
}
std::cout << "]\n";
} else {
++end;
for(const int* ptr = begin; ptr >= end; --ptr) {
if((count == constraint) && (constraint != 0)) {
count = 0;
std::cout << "...\n ";
}
std::cout << *ptr;
if(ptr != end) { std::cout << ", "; }
if(ptr == end) { break; }
++count;
}
std::cout << "]\n";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

}
}
Loading
Loading