Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
520e4ac
feat: implement tasks
ilyamikhailov16 Nov 27, 2025
01cb3a4
Merge remote-tracking branch 'upstream/main'
ilyamikhailov16 Dec 9, 2025
d453f8b
feat: implement second week tasks
ilyamikhailov16 Dec 9, 2025
6bf278a
feat: implement second week remaining tasks
ilyamikhailov16 Dec 10, 2025
7030e8b
Merge branch 'main' of github.com:psds-cpp/psds-cpp-2025
ilyamikhailov16 Dec 20, 2025
a4bfdbf
feat: implement third week tasks
ilyamikhailov16 Dec 21, 2025
1a22f2b
Merge branch 'main' of github.com:psds-cpp/psds-cpp-2025
ilyamikhailov16 Dec 24, 2025
5aa3581
feat: implement 4 week tasks
ilyamikhailov16 Dec 26, 2025
7505ec7
fix mistakes
ilyamikhailov16 Dec 26, 2025
57d12f5
Update check_flags.cpp
ilyamikhailov16 Feb 8, 2026
eea9f87
Update rms.cpp
ilyamikhailov16 Feb 8, 2026
939790e
Update addition.cpp
ilyamikhailov16 Feb 8, 2026
8fa735a
Rename write/read variables to pos_write/pos_read
ilyamikhailov16 Feb 8, 2026
a6df4eb
Update char_changer.cpp
ilyamikhailov16 Feb 8, 2026
876338a
Update char_changer.cpp
ilyamikhailov16 Feb 8, 2026
adf1073
Fix null terminator position in char_changer
ilyamikhailov16 Feb 8, 2026
8f2fe09
Refactor CharChanger function to improve readability and efficiency
ilyamikhailov16 Feb 8, 2026
d5f22a7
Refactor PrintCheckFlags function to enhance output formatting
ilyamikhailov16 Feb 8, 2026
f116bf5
Update README.md to clarify return pointer behavior in predicate func…
ilyamikhailov16 Feb 8, 2026
ea3bb07
Fix FindLastElement function to correctly initialize last_element poi…
ilyamikhailov16 Feb 8, 2026
160fb37
Refactor FindLastElement function to improve return logic
ilyamikhailov16 Feb 8, 2026
b7613d4
Refactor PrintMemory functions to simplify byte handling and improve …
ilyamikhailov16 Feb 8, 2026
7d7117b
Refactor FindLongestSubsequence function to simplify pointer handling
ilyamikhailov16 Feb 8, 2026
450cc1a
Enhance FindLongestSubsequence function with overload for non-const c…
ilyamikhailov16 Feb 8, 2026
9a5d1b1
Refactor PrintArray function to enhance clarity and efficiency
ilyamikhailov16 Feb 8, 2026
5784369
Refactor CalculateDataStats function to accept a const reference for …
ilyamikhailov16 Feb 8, 2026
15c75f2
Refactor Date and StudentInfo structs to simplify comparison operators
ilyamikhailov16 Feb 8, 2026
700b226
Refactor PrintCheckFlags function to simplify output logic
ilyamikhailov16 Feb 8, 2026
fed1b0f
Enhance Unique function by reserving space for result vector to impro…
ilyamikhailov16 Feb 8, 2026
5baf83c
Refactor Stack class methods for improved efficiency and readability
ilyamikhailov16 Feb 8, 2026
ddc54ba
Refactor RingBuffer methods for improved efficiency and clarity
ilyamikhailov16 Feb 8, 2026
f2abe8b
Refactor Queue class equality operator for improved efficiency and cl…
ilyamikhailov16 Feb 8, 2026
890adb7
Refactor Queue class Swap method for improved efficiency
ilyamikhailov16 Feb 8, 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
5 changes: 2 additions & 3 deletions 01_week/tasks/addition/addition.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <cstdint>
#include <stdexcept>


int64_t Addition(int a, int b) {
throw std::runtime_error{"Not implemented"};
}
return static_cast<int64_t>(a) + b;
}
46 changes: 43 additions & 3 deletions 01_week/tasks/char_changer/char_changer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
#include <cstddef>
#include <stdexcept>
#include <cctype>


size_t CharChanger(char array[], size_t size, char delimiter = ' ') {
throw std::runtime_error{"Not implemented"};
size_t CharChanger(char array[], size_t, char delimiter = ' ') {
int counterRepeatedSymbols = 1; // Счётчик повторяющихся символов
int pos_write = 0; // Индекс для записи обработанного символа
char repeating_symbol = array[0]; // В процессе выполнения - предыдущий символ(отслеживаем повторения)

for (char* ptr = array + 1; repeating_symbol != '\0'; ++ptr) {
if (repeating_symbol == *ptr){
++counterRepeatedSymbols;
continue;
}

if (isalpha(repeating_symbol)){
array[pos_write] = toupper(repeating_symbol);
} else if (isdigit(repeating_symbol)){
array[pos_write] = '*';
} else if (repeating_symbol == ' '){
array[pos_write] = delimiter;
} 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:

  1. Не придется листать много кода, что увидеть действие перед переходом на следующую итерацию цикла, либо даже лучше переписать на for
  2. Можно будет убрать else и лишний уровень вложенности

array[pos_write] = '_';
}
++pos_write;


if (repeating_symbol == ' ') {
counterRepeatedSymbols = 1;
}

if (counterRepeatedSymbols >= 10){
counterRepeatedSymbols = 0;
}

if (counterRepeatedSymbols != 1){
array[pos_write] = static_cast<char>(counterRepeatedSymbols + '0'); // Преобразуем число в символ
counterRepeatedSymbols = 1;
++pos_write;
}

repeating_symbol = *ptr;
}

array[pos_write] = '\0';
return pos_write;
}
3 changes: 1 addition & 2 deletions 01_week/tasks/check_flags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

Если передан флаг отсутствия проверок, то необходимо вывести пустые `[]`.

Если передано значение выходит из возможного диапазона значений, то вывод
следует оставить пустым.
Если переданное значение выходит из возможного диапазона значений, то вывод следует оставить пустым.
46 changes: 44 additions & 2 deletions 01_week/tasks/check_flags/check_flags.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <cstdint>
#include <stdexcept>
#include <iostream>


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

void PrintCheckFlags(CheckFlags flags) {
throw std::runtime_error{"Not implemented"};
if (flags == CheckFlags::NONE) {
std::cout << "[]";
return;
}

if ((static_cast<uint8_t>(flags) & ~static_cast<uint8_t>(CheckFlags::ALL)) != 0) {
std::cout << "";
return;
}

std::cout << "[";
bool first = true;
if ((static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::TIME)) != 0) {
if (!first) std::cout << ",";
std::cout << "TIME";
first = false;
}
if ((static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::DATE)) != 0) {
if (!first) std::cout << ",";
std::cout << "DATE";
first = false;
}
if ((static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::USER)) != 0) {
if (!first) std::cout << ",";
std::cout << "USER";
first = false;
}
if ((static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::CERT)) != 0) {
if (!first) std::cout << ",";
std::cout << "CERT";
first = false;
}
if ((static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::KEYS)) != 0) {
if (!first) std::cout << ",";
std::cout << "KEYS";
first = false;
}
if ((static_cast<uint8_t>(flags) & static_cast<uint8_t>(CheckFlags::DEST)) != 0) {
if (!first) std::cout << ",";
std::cout << "DEST";
first = false;
}
std::cout << "]";
}
67 changes: 67 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <string>


// Константы для преобразования
constexpr long double IN_TO_CM = 2.54L;
constexpr long double FT_TO_IN = 12.0L;
constexpr long double M_TO_CM = 100.0L;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Это правильный подход, добавить константы


// ft -> in
double operator"" _ft_to_in(long double ft_value) {
return static_cast<double>(ft_value * FT_TO_IN);
}

// ft -> cm
double operator"" _ft_to_cm(long double ft_value) {
return static_cast<double>(ft_value * FT_TO_IN * IN_TO_CM);
}

// ft -> m
double operator"" _ft_to_m(long double ft_value) {
return static_cast<double>(ft_value * FT_TO_IN * IN_TO_CM / M_TO_CM);
}

// in -> ft
double operator"" _in_to_ft(long double in_value) {
return static_cast<double>(in_value / FT_TO_IN);
}

// in -> cm
double operator"" _in_to_cm(long double in_value) {
return static_cast<double>(in_value * IN_TO_CM);
}

// in -> m
double operator"" _in_to_m(long double in_value) {
return static_cast<double>(in_value * IN_TO_CM / M_TO_CM);
}

// cm -> ft
double operator"" _cm_to_ft(long double cm_value) {
return static_cast<double>(cm_value / IN_TO_CM / FT_TO_IN);
}

// cm -> in
double operator"" _cm_to_in(long double cm_value) {
return static_cast<double>(cm_value / IN_TO_CM);
}

// cm -> m
double operator"" _cm_to_m(long double cm_value) {
return static_cast<double>(cm_value / M_TO_CM);
}

// m -> ft
double operator"" _m_to_ft(long double m_value) {
return static_cast<double>(m_value * M_TO_CM / IN_TO_CM / FT_TO_IN);
}

// m -> in
double operator"" _m_to_in(long double m_value) {
return static_cast<double>(m_value * M_TO_CM / IN_TO_CM);
}

// m -> cm
double operator"" _m_to_cm(long double m_value) {
return static_cast<double>(m_value * M_TO_CM);
}
26 changes: 23 additions & 3 deletions 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>
#include <vector>


void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
}
if (bytes <= 0 || bytes > 8) {
return;
}

std::cout << "0b";

// Выводим биты, начиная со старшего
for (int i = bytes * 8 - 1; i >= 0; --i) {
// "Выталкиваем" все биты, кроме i-ого, так чтобы i-ый был последним и выводим этот бит
if ((value >> i) & 1) {
std::cout << 1;
} else {
std::cout << 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.

Можно 5 строк заменитьтернарным оператор выводить в поток по условию 1 или 0, будет компактнее


if (i != 0 && i % 4 == 0) {
std::cout << "'";
}
}
std::cout << '\n';
}
33 changes: 31 additions & 2 deletions 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
#include <stdexcept>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm> // Для std::min и std::max


void SolveQuadratic(int a, int b, int c) {
throw std::runtime_error{"Not implemented"};
if (a == 0) {
if (b == 0) {
if (c == 0) {
std::cout << "infinite solutions";
} else {
std::cout << "no solutions";
}
} else {
double x = static_cast<double>(-c) / b;
std::cout << std::defaultfloat << std::setprecision(6) << x;
}
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 {
long long discriminant = static_cast<long long>(b) * b - 4 * static_cast<long long>(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.

Понятно для чего так сделано, но не лучше хранить дискриминант в double в данном случае


if (discriminant > 0) {
double x1 = (-b - std::sqrt(static_cast<double>(discriminant))) / (2 * a);
double x2 = (-b + std::sqrt(static_cast<double>(discriminant))) / (2 * a);
std::cout << std::defaultfloat << std::setprecision(6) << std::min(x1, x2);
std::cout << " ";
std::cout << std::defaultfloat << std::setprecision(6) << std::max(x1, x2);
} else if (discriminant == 0) {
double x = static_cast<double>(-b) / (2 * a);
std::cout << std::defaultfloat << std::setprecision(6) << x;
} else {
std::cout << "no solutions";
}
}
}
15 changes: 11 additions & 4 deletions 01_week/tasks/rms/rms.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#include <cstdef>
#include <stdexcept>
#include <cstddef>
#include <cmath>


double CalculateRMS(double values[], size_t size) {
throw std::runtime_error{"Not implemented"};
}
if (size <= 0 || values == nullptr){ return 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.

отсутствует пробел перед {


double sum = 0;
for (size_t i=0; i < size; ++i){
sum+=std::pow(values[i], 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.

нет пробелов вокруг арифметических операторов и инициализации i

}

return std::sqrt(sum / size);
}
19 changes: 16 additions & 3 deletions 02_week/tasks/func_array/func_array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#include <stdexcept>
#include <cstddef>

using funcPtr = double (*)(double, double);

double ApplyOperations(double a, double b /* other arguments */) {
throw std::runtime_error{"Not implemented"};
double ApplyOperations(const double a, const double b, funcPtr* arr, size_t funcArraySize) {
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 (arr == nullptr || funcArraySize <= 0){
return 0.0;
}

double cumulative_result = 0;
for (unsigned int i=0; i < funcArraySize; ++i){
Copy link
Contributor Author

@18thday 18thday Jan 5, 2026

Choose a reason for hiding this comment

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

пробелы вокруг =

if (arr[i] == nullptr){
continue;
}
cumulative_result+=arr[i](a, 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.

пробелы вокруг оператора +=

}

return cumulative_result;
}
25 changes: 22 additions & 3 deletions 02_week/tasks/last_of_us/last_of_us.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#include <stdexcept>
#include <cstddef>

using funcPtr = bool (*)(int);

/* 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, funcPtr predicate) {
if (begin == nullptr || end == nullptr || predicate == nullptr){
return end;
}

if (begin >= end){
return end;
}

const int* last_element = end;

while (begin < end)
{
--end;
if (predicate(*end)){
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.

можно упростить алгоритм поскольку нам нужен последний, быстрее идти с конца и при первом срабатывании сразу возвращать из функции нужный указатель

}

return last_element;
}
47 changes: 42 additions & 5 deletions 02_week/tasks/little_big/little_big.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm>


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

std::cout << "0x";
if (inversion) {
// Читаем байты в обратном порядке сразу при выводе
for (size_t i = sizeof(int); i > 0; --i) {
std::cout << std::hex << std::uppercase
<< std::setfill('0') << std::setw(2)
<< static_cast<unsigned int>(bytes[i-1]);
}
} else {
for (size_t i = 0; i < sizeof(int); ++i) {
std::cout << std::hex << std::uppercase
<< std::setfill('0') << std::setw(2)
<< static_cast<unsigned int>(bytes[i]);
}
}
std::cout << std::dec << std::endl;
}

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

std::cout << "0x";
if (inversion) {
// Читаем байты в обратном порядке сразу при выводе
for (size_t i = sizeof(double); i > 0; --i) {
std::cout << std::hex << std::uppercase
<< std::setfill('0') << std::setw(2)
<< static_cast<unsigned int>(bytes[i-1]);
}
} else {
for (size_t i = 0; i < sizeof(double); ++i) {
std::cout << std::hex << std::uppercase
<< std::setfill('0') << std::setw(2)
<< static_cast<unsigned int>(bytes[i]);
}
}
std::cout << std::dec << 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.

Это задание было конечно на reinterpret_cast, что позволило бы не создавать буфер копию текущего значения. Но даже так, зачем в данном случае полное дублирование?
Лучше было написать ещё одну функцию, которая бы принимала буффер, размер и флаг и вызывалась бы из данных функций

}
Loading