Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
05f634a
Update addition.cpp
Rygrotten Nov 28, 2025
c1917a1
Add files via upload
Rygrotten Nov 28, 2025
4d776aa
Add files via upload
Rygrotten Nov 28, 2025
0b5b0cf
add rms
Rygrotten Nov 28, 2025
9c2e6d1
add print_bits
Rygrotten Nov 28, 2025
64105b2
fix print bits
Rygrotten Nov 28, 2025
8693a72
add check flags
Rygrotten Nov 28, 2025
92b781c
add length lit
Rygrotten Nov 28, 2025
eb97186
Update length_lit.cpp
Rygrotten Nov 28, 2025
5ebb519
Update 2 length_lit.cpp
Rygrotten Nov 28, 2025
98f7b0b
Update 3 length_lit.cpp
Rygrotten Nov 28, 2025
32d3368
Update length_lit.cpp
Rygrotten Nov 28, 2025
887a093
add quadratic
Rygrotten Nov 28, 2025
e9853e4
Merge branch 'psds-cpp:main' into main
Rygrotten Dec 9, 2025
afdacf7
Func_array attempt 1
Rygrotten Dec 9, 2025
7acc01e
Last of us attempt 1
Rygrotten Dec 9, 2025
46c4f81
Longest attempt 1
Rygrotten Dec 9, 2025
4df22bb
Swap_ptr attempt 2
Rygrotten Dec 9, 2025
68129b4
Pretty array attempt 2
Rygrotten Dec 9, 2025
4b035c8
Enum operators 1
Rygrotten Dec 19, 2025
c16f030
Easy compare attempt 2
Rygrotten Dec 19, 2025
aa36ec4
minmax attempt 1
Rygrotten Dec 19, 2025
fb2e26d
range attempt 1
Rygrotten Dec 19, 2025
1b1360b
unique attempt 1
Rygrotten Dec 19, 2025
86efdf4
data stats attempt 1
Rygrotten Dec 19, 2025
1f6bca4
filter attempt 1
Rygrotten Dec 19, 2025
0cf4e9c
find all attempt 1
Rygrotten Dec 19, 2025
b14a286
Stack attempt 1
Rygrotten Dec 26, 2025
f644ce2
Queue attempt 1
Rygrotten Dec 26, 2025
3557ab2
RingBuffer attempt 1
Rygrotten Dec 26, 2025
f3c5e4b
Phasor attempt 1
Rygrotten Dec 26, 2025
7e663dc
Merge pull request #2 from Rygrotten/Phasor1
Rygrotten Jan 22, 2026
e56d485
Merge pull request #3 from Rygrotten/RingBuffer1
Rygrotten Jan 22, 2026
5acad0a
Merge pull request #4 from Rygrotten/Queue1
Rygrotten Jan 22, 2026
4f80bcd
Merge pull request #5 from Rygrotten/Stack1
Rygrotten Jan 22, 2026
34fa6ac
Merge pull request #6 from Rygrotten/find-all-1
Rygrotten Jan 22, 2026
935fd58
Merge pull request #7 from Rygrotten/filter-attempt-1
Rygrotten Jan 22, 2026
eb4892a
Merge pull request #8 from Rygrotten/data-stats-attempt-1
Rygrotten Jan 22, 2026
9a84272
Merge pull request #9 from Rygrotten/unique-attempt-1
Rygrotten Jan 22, 2026
39d1ff7
Merge pull request #10 from Rygrotten/range-attempt-1
Rygrotten Jan 22, 2026
fc75705
Merge pull request #11 from Rygrotten/Longest1
Rygrotten Jan 22, 2026
59d3cd1
Merge pull request #12 from Rygrotten/LastOfUs1
Rygrotten Jan 22, 2026
ee77fe1
Merge pull request #13 from Rygrotten/minmax-attempt-1
Rygrotten Jan 22, 2026
da25729
Merge pull request #14 from Rygrotten/Easy-compare-2
Rygrotten Jan 22, 2026
f2a213f
Merge pull request #15 from Rygrotten/Enum-operators-1
Rygrotten Jan 22, 2026
113ab71
Merge pull request #17 from Rygrotten/Pretty_array2
Rygrotten Jan 22, 2026
76f3e6e
Merge pull request #18 from Rygrotten/Swap_ptr2
Rygrotten Jan 22, 2026
2ed52ca
Merge pull request #19 from Rygrotten/FuncArray1
Rygrotten Jan 22, 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
6 changes: 4 additions & 2 deletions 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 one = static_cast<int64_t>(a);
int64_t two = static_cast<int64_t>(b);
return one + two;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

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


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),
ALL = TIME | DATE | USER | CERT | KEYS | DEST
};

void PrintCheckFlags(CheckFlags flags) {
throw std::runtime_error{"Not implemented"};
}
#include <cstdint>
#include <stdexcept>


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),
ALL = TIME | DATE | USER | CERT | KEYS | DEST
};

void PrintCheckFlags(CheckFlags flags) {
uint8_t value = static_cast<uint8_t>(flags);
const uint8_t valid_mask = 0x3F; // 0b00111111
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 (value & ~valid_mask) {
std::cout << "";
return;
}

std::string output = "[";
const char* separator = "";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

почему не char ?


auto add_flag = [&](CheckFlags flag, const char* name) {
if (value & static_cast<uint8_t>(flag)) {
output += separator;
output += name;
separator = ",";
}
};

add_flag(CheckFlags::TIME, "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.

имя не подходящее, не отражает сути

add_flag(CheckFlags::DATE, "DATE");
add_flag(CheckFlags::USER, "USER");
add_flag(CheckFlags::CERT, "CERT");
add_flag(CheckFlags::KEYS, "KEYS");
add_flag(CheckFlags::DEST, "DEST");

output += "]";
std::cout << output;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

}
53 changes: 53 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <cmath>

constexpr double operator "" _ft_to_m(long double value) {
return static_cast<double>(value * 0.3048);
}

constexpr double operator "" _ft_to_cm(long double value) {
return static_cast<double>(value * 30.48);
}

constexpr double operator "" _ft_to_in(long double value) {
return static_cast<double>(value * 12.0);
}

constexpr double operator "" _in_to_m(long double value) {
return static_cast<double>(value * 0.0254);
}

constexpr double operator "" _in_to_cm(long double value) {
return static_cast<double>(value * 2.54);
}

constexpr double operator "" _in_to_ft(long double value) {
return static_cast<double>(value / 12.0);
}

constexpr double operator "" _m_to_ft(long double value) {
return static_cast<double>(value / 0.3048);
}

constexpr double operator "" _m_to_in(long double value) {
return static_cast<double>(value / 0.0254);
}

constexpr double operator "" _m_to_cm(long double value) {
return static_cast<double>(value * 100.0);
}

constexpr double operator "" _cm_to_m(long double value) {
return static_cast<double>(value * 0.01);
}

constexpr double operator "" _cm_to_ft(long double value) {
return static_cast<double>(value / 30.48);
}

constexpr double operator "" _cm_to_in(long double value) {
return static_cast<double>(value / 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.

magic value не принято в коде использовать, стоило вынести в константы 12, 0.3048, 0.0254 ... с понятными именами и в выражениях использовать. константы можно поместить в безымянный namespace, чтобы видимость ограничивалась данным файлом

}



36 changes: 29 additions & 7 deletions 01_week/tasks/print_bits/print_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
#include <cstddef>
#include <stdexcept>


void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
}
#include <iostream>

void PrintBits(long long value, size_t bytes) {
if (bytes == 0 || bytes > 8) {
return;
}

const size_t total_bits = bytes * 8;
unsigned long long unsigned_value = value;

std::cout << "0b";

for (size_t i = 0; i < total_bits; ++i) {
size_t bit_pos = total_bits - 1 - i;
unsigned long long mask = 1ULL << bit_pos;

if (unsigned_value & mask) {
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.

это тернарный оператор


if ((i + 1) % 4 == 0 && i != total_bits - 1) {
std::cout << "'";
}
}

std::cout << '\n';
}
60 changes: 55 additions & 5 deletions 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
#include <stdexcept>


void SolveQuadratic(int a, int b, int c) {
throw std::runtime_error{"Not implemented"};
#include <iostream>
#include <iomanip>
#include <cmath>
#include <utility>

void SolveQuadratic(int a, int b, int c) {
std::cout << std::setprecision(6);

if (a == 0 && b == 0 && c == 0) {
std::cout << "infinite solutions";
return;
}

if (a == 0 && b == 0 && c != 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.

третья проверка лишняя, так как после первой проверки уже звестно что c != 0

std::cout << "no solutions";
return;
}

if (a == 0) {
double root = -static_cast<double>(c) / b;

if (root == 0.0) root = 0.0;

std::cout << root;
return;
}

double discr = static_cast<double>(b) * b - 4.0 * a * c;

if (discr < 0) {
std::cout << "no solutions";
return;
}

if (discr == 0) {
double root = -static_cast<double>(b) / (2.0 * a);

if (root == 0.0) root = 0.0;

std::cout << root;
return;
}

double sqrt_d = std::sqrt(discr);
double root1 = (-static_cast<double>(b) - sqrt_d) / (2.0 * a);
double root2 = (-static_cast<double>(b) + sqrt_d) / (2.0 * a);

if (root1 > root2) {
std::swap(root1, root2);
}

if (root1 == 0.0) root1 = 0.0;
if (root2 == 0.0) root2 = 0.0;

std::cout << root1 << " " << root2;
}
24 changes: 18 additions & 6 deletions 01_week/tasks/rms/rms.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#include <cstdef>
#include <stdexcept>


double CalculateRMS(double values[], size_t size) {
throw std::runtime_error{"Not implemented"};
#include <cstddef>
#include <stdexcept>
#include <cmath>



double CalculateRMS(double values[], size_t size) {
if (values == nullptr || size == 0) {
return 0.0;
}

double sum = 0.0;
for (size_t i = 0; i < size; ++i) {
sum += values[i] * values[i];
}

double sqavg = sum / size;
return std::sqrt(sqavg);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

}
19 changes: 14 additions & 5 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"};
#include <stdexcept>

double ApplyOperations(double a, double b, double (**operations)(double, double), size_t n) {
double total = 0.0;

if (operations == nullptr || n == 0) {
return total;}
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 (size_t i = 0; i < n; ++i) {
if (operations[i] != 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.

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

total += operations[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 total;
}
24 changes: 20 additions & 4 deletions 02_week/tasks/last_of_us/last_of_us.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#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)(int)) {

if (begin == nullptr || end == nullptr || begin > 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.

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

return end;
}

const int* last_found = end;

// Проходим по массиву с конца к началу
const int* current = end;
while (current > begin) {
--current;
if (predicate(*current)) {
last_found = current;
break;
}
}

Copy link
Contributor Author

@18thday 18thday Jan 23, 2026

Choose a reason for hiding this comment

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

в целом хорошо, но можно было обойтись без дополнительного указателя last_found, в конце возвращать end, а в теле возвращать current при совпадении

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

template<typename CharType>
CharType* FindLongestSubsequenceImpl(CharType* begin, CharType* end, size_t& count) {
if (begin == nullptr || end == nullptr || begin > end) {
count = 0;
return nullptr;
}

if (begin == end) {
count = 0;
return 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.

можно объединить условия, действия одинаковые и в каждом из случаев считаем входные указатели не валидными


CharType* longest_start = begin;
size_t longest_length = 1;
CharType* current_start = begin;
size_t current_length = 1;

for (CharType* ptr = begin; ptr < end - 1; ++ptr) {
if (*ptr == *(ptr + 1)) {
current_length++;
} else {
if (current_length > longest_length) {
longest_length = current_length;
longest_start = current_start;
}
current_start = ptr + 1;
current_length = 1;
}
}

if (current_length > longest_length) {
longest_length = current_length;
longest_start = current_start;
}

count = longest_length;
return longest_start;
}

const char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) {
return FindLongestSubsequenceImpl(begin, end, count);
}

/* return_type */ FindLongestSubsequence(/* ptr_type */ begin, /* ptr_type */ end, /* type */ count) {
throw std::runtime_error{"Not implemented"};
char* FindLongestSubsequence(char* begin, char* end, size_t& count) {
return FindLongestSubsequenceImpl(begin, end, 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.

если это шаблонная функция, зачем тогда данные версии?

}
Loading
Loading