Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7e5f6fd
add (solution): add addition task
GanjaMember Nov 28, 2025
918f221
add (solution): add rms task
GanjaMember Nov 28, 2025
674d723
add (solution): add quadratic task
GanjaMember Nov 28, 2025
3e0971d
add (solution): add print_bits task
GanjaMember Nov 28, 2025
8888db2
add (solution): add length_lit task
GanjaMember Nov 28, 2025
6ba1cc7
add (solution): add check_flags task
GanjaMember Nov 28, 2025
03782e6
add (solution): add char_changer task
GanjaMember Nov 28, 2025
6d671ea
add (github): add .gitignore file
GanjaMember Dec 3, 2025
c36c0b9
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
GanjaMember Dec 3, 2025
2b0311d
update (github): add main.cpp in .gitignore
GanjaMember Dec 3, 2025
a1eb37d
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
GanjaMember Dec 3, 2025
2901a4a
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
GanjaMember Dec 3, 2025
70b6212
add (solution): add func_array task
GanjaMember Dec 3, 2025
fcce802
add (solution): add last_of_us task
GanjaMember Dec 3, 2025
3b1e4ba
add (solution): add little_big task
GanjaMember Dec 3, 2025
f316b43
add (solution): add longest task
GanjaMember Dec 3, 2025
c187692
add (solution): add pretty_array task
GanjaMember Dec 3, 2025
bef6f6f
add (solution): add swap_ptr task
GanjaMember Dec 3, 2025
7942e20
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
GanjaMember Dec 11, 2025
4e843ca
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
GanjaMember Dec 16, 2025
b5e6048
add (solution): add data_stats task
GanjaMember Dec 16, 2025
8bec754
add (solution): add easy_compare task
GanjaMember Dec 16, 2025
99f7f9f
add (solution): add enum_operators task
GanjaMember Dec 16, 2025
d56fc84
add (solution): add filter task
GanjaMember Dec 16, 2025
6c80a35
add (solution): add find_all task
GanjaMember Dec 16, 2025
495147e
add (solution): add minmax task
GanjaMember Dec 16, 2025
3aca2a2
add (solution): add os_overload task
GanjaMember Dec 16, 2025
fd63ae4
add (solution): add range task
GanjaMember Dec 16, 2025
da78a7e
add (solution): add unique task
GanjaMember Dec 16, 2025
1769325
chore: remove incomplete 04_week directory
GanjaMember Dec 16, 2025
c8693f4
fix (solution): fix infinite loop in range task
GanjaMember Dec 16, 2025
18eedf4
fix (solution): reduce number of comparisons to increase performance …
GanjaMember Dec 17, 2025
5321d62
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
GanjaMember Dec 26, 2025
bf4e7b8
add (solution): add ring_buffer task
GanjaMember Dec 26, 2025
70ff77d
add (solution): add phasor task
GanjaMember Dec 26, 2025
fca57cf
add (solution): add queue task
GanjaMember Dec 26, 2025
171b60e
add (solution): add stack task
GanjaMember Dec 26, 2025
a178ff3
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
GanjaMember Dec 26, 2025
77b1676
ref (solution): remove explicit static_cast of the second operand
GanjaMember Dec 29, 2025
b0b0dfa
ref (solution): rename variable 'k' to variable 'pos'
GanjaMember Dec 29, 2025
3ff4083
ref (solution): rewrite ineffective solution
GanjaMember Dec 29, 2025
f8ab7f0
ref (solution): create anonymous namespace with conversion constants
GanjaMember Dec 29, 2025
6f857f6
ref (solution): remove dynamic array buffer and output directly
GanjaMember Dec 29, 2025
1f9e7b4
ref (solution): remove redundant variables initialization
GanjaMember Dec 29, 2025
d9fe492
ref (solution): specify std namespace for sqrt function
GanjaMember Dec 29, 2025
8c9fa30
ref (solution): remove redundant const qualifiers in the function sig…
GanjaMember Dec 29, 2025
e586b20
ref (solution): resolve undefined behaviour with const_cast
GanjaMember Dec 29, 2025
8938cfc
ref (solution): create a common function for int and double and use t…
GanjaMember Dec 29, 2025
654d495
ref (solution): add const qualifier for returned value to correct sig…
GanjaMember Dec 29, 2025
05ec36a
ref (solution): use ternary operators to avoid code duplication
GanjaMember Dec 29, 2025
5620c8c
ref (solution): specify std namespace for sqrt function
GanjaMember Dec 29, 2025
35ad4a7
ref (solution): pass struct by reference and replace if-branching wit…
GanjaMember Dec 29, 2025
6b59a9e
ref (solution): rewrite ineffective flags output algorithm
GanjaMember Dec 29, 2025
fbf46da
ref (solution): reserve memory only after checking for early function…
GanjaMember Dec 29, 2025
216a1ff
fix (solution): include necessary library
GanjaMember Dec 29, 2025
07c7f8d
ref (solution): avoid code duplication using ternary operators
GanjaMember Dec 29, 2025
508d5a7
ref (solution): unify style of fields initialization and join separat…
GanjaMember Dec 29, 2025
757ff8e
fix (solution): comply with test awaiting return of pointer to non-co…
GanjaMember Dec 29, 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
build-asan
.vscode
main
main.cpp
3 changes: 1 addition & 2 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;
}
50 changes: 48 additions & 2 deletions 01_week/tasks/char_changer/char_changer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
#include <cstddef>
#include <stdexcept>
#include <locale>


size_t CharChanger(char array[], size_t size, char delimiter = ' ') {
throw std::runtime_error{"Not implemented"};
// pos - позиция в массиве array без дубликатов
size_t pos = 0;

// size - размер массива с учётом '\0' в конце
for (size_t i = 0; i < size - 1; ++i) {
// сохраняем символ до его замены и приводим его к uint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

много лишних комментариев

// функции isdigit, islower и др. не работают с отрицательным кодами
char old_symbol = static_cast<unsigned int>(array[i]);

// определяем тип замены
if (isdigit(old_symbol)) {
array[pos++] = '*';
}
else if (old_symbol == ' ') {
array[pos++] = delimiter;
}
else if (islower(old_symbol)) {
array[pos++] = toupper(old_symbol);
}
else if (isupper(old_symbol)) {
array[pos++] = old_symbol;
}
else {
array[pos++] = '_';
}

// поиск и подсчёт дубликатов
size_t j = i + 1;
while (j < size && array[j] == old_symbol) {
++j;
}

// если есть дубликаты
if (size_t duplicates = j - i - 1; duplicates > 0) {
// обновляем указатель i
i += duplicates;

// добавляем счётчик после повторяющегося символа (кроме ' ')
if (old_symbol != ' ')
array[pos++] = duplicates + 1 >= 10 ? '0' : duplicates + 1 + '0';
}
}

// устанавливаем новый конец массива
array[pos] = '\0';

return pos;
}
41 changes: 38 additions & 3 deletions 01_week/tasks/check_flags/check_flags.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cstdint>
#include <stdexcept>

#include <string>
#include <utility>
#include <iostream>

enum class CheckFlags : uint8_t {
NONE = 0,
Expand All @@ -13,6 +14,40 @@ enum class CheckFlags : uint8_t {
ALL = TIME | DATE | USER | CERT | KEYS | DEST
};

CheckFlags operator&(CheckFlags lhs, CheckFlags rhs) {
return static_cast<CheckFlags>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
}

void PrintCheckFlags(CheckFlags flags) {
throw std::runtime_error{"Not implemented"};
// Проверка на выход за диапозон значений CheckFlags
if ((~static_cast<uint8_t>(CheckFlags::ALL) & static_cast<uint8_t>(flags)) != 0) {
return;
}

const static std::pair<CheckFlags, std::string> checks[] {
{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.

выглядит не очень эффективно, каждый раз создавать вектор


bool first = true;

std::cout << "[";

for (const auto& [flag, name] : checks) {
if ((flags & flag) != CheckFlags::NONE) {
if (first) {
first = false;
}
else {
std::cout << ",";
}
std::cout << name;
}
}

std::cout << ']';
}
60 changes: 60 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace {
constexpr long double INCHES_PER_FOOT = 12.0L;
constexpr long double CM_PER_INCH = 2.54L;
constexpr long double M_PER_FOOT = 0.3048L;
constexpr long double CM_PER_FOOT = M_PER_FOOT * 100.0L;
constexpr long double M_PER_INCH = CM_PER_INCH / 100.0L;
constexpr long double CM_PER_METER = 100.0L;
}

// ==== Перевод футов ====
constexpr long double operator""_ft_to_m(long double ft) {
return ft * M_PER_FOOT;
}

constexpr long double operator""_ft_to_cm(long double ft) {
return ft * CM_PER_FOOT;
}

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

// ==== Перевод дюймов ====
constexpr long double operator""_in_to_m(long double in) {
return in * M_PER_INCH;
}

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

constexpr long double operator""_in_to_ft(long double in) {
return in / INCHES_PER_FOOT;
}

// ==== Перевод метров ====
constexpr long double operator""_m_to_ft(long double m) {
return m / M_PER_FOOT;
}

constexpr long double operator""_m_to_in(long double m) {
return m / M_PER_INCH;
}

constexpr long double operator""_m_to_cm(long double m) {
return m * CM_PER_METER;
}

// ==== Перевод сантиметров ====
constexpr long double operator""_cm_to_m(long double cm) {
return cm / CM_PER_METER;
}

constexpr long double operator""_cm_to_ft(long double cm) {
return cm / CM_PER_FOOT;
}

constexpr long double operator""_cm_to_in(long double cm) {
return cm / CM_PER_INCH;
}
21 changes: 18 additions & 3 deletions 01_week/tasks/print_bits/print_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
#include <cstddef>
#include <stdexcept>
#include <stddef.h>
#include <iostream>


void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
size_t bits = bytes * 8;
unsigned long long bit_index = 1ll << (bits - 1); // 0b1000'...'0000
size_t delims = 1 + 2 * (bytes - 1);
// Выделяем буфер под биты, апострофы и '\0' в конце
size_t buffer_size = bits + delims + 1;

std::cout << "0b";
for (size_t i = 0; i < buffer_size - 1; ++i) {
if (i % 5 == 4) {
std::cout << '\'';
} else {
std::cout << static_cast<char>(static_cast<bool>(value & bit_index) + '0');
bit_index = bit_index >> 1;
}
}
std::cout << std::endl;
}
35 changes: 33 additions & 2 deletions 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
#include <stdexcept>
#include <iomanip>
#include <iostream>
#include <cmath>


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;
}

if (a == 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.

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

b != 0 ? std::cout << -(static_cast<double>(c) / b) : std::cout << "no solutions";
return;
}

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

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

if (discriminant > 0) {
double sqrt_d = std::sqrt(discriminant);
double x1 = (-b - sqrt_d) / (2.0 * a);
double x2 = (-b + sqrt_d) / (2.0 * a);
std::cout << std::setprecision(6) << x1 << ' ' << x2;
}
else if (discriminant == 0) {
double x = -b / (2.0 * a);
std::cout << std::setprecision(6) << x;
}
else {
std::cout << "no solutions";
}
}
13 changes: 10 additions & 3 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 <cmath>


double CalculateRMS(double values[], size_t size) {
throw std::runtime_error{"Not implemented"};
if (size == 0 || values == nullptr) return .0;

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

// size неявно преобразуется к double
return std::sqrt(result / size);
}
15 changes: 12 additions & 3 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>
#include <cstddef>


double ApplyOperations(double a, double b /* other arguments */) {
throw std::runtime_error{"Not implemented"};
double ApplyOperations(double a, double b, double (*func_arr[])(double, double), size_t size) {
if (size == 0) return 0;

double result = 0;

for (size_t i = 0; i < size; ++i) {
if (func_arr[i])
result += func_arr[i](a, b);
}

return result;
}
30 changes: 27 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,30 @@
#include <stdexcept>
#include <cstddef>

const int* FindLastElement(const int* begin, const int* end, bool (*predicate)(int)) {
if (!begin || !end || !predicate || begin > end)
return end;

/* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) {
throw std::runtime_error{"Not implemented"};
const int* last = end;

for (; begin < end; ++begin) {
if (predicate(*begin)) {
last = begin;
}
}

return last;
}

int* FindLastElement(int* begin, int* end, bool (*predicate)(int)) {
return const_cast<int*>(
FindLastElement(
const_cast<const int*>(begin),
const_cast<const int*>(end),
predicate
)
);
}

inline int* FindLastElement(std::nullptr_t, std::nullptr_t, bool (*)(int)) {
return nullptr;
}
26 changes: 20 additions & 6 deletions 02_week/tasks/little_big/little_big.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
#include <stdexcept>
#include <iostream>
#include <iomanip>

void PrintMemory(const u_char* begin, size_t size, bool is_little_endian) {
const u_char* end = begin + size;

void PrintMemory(int /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
std::cout << "0x" << std::hex << std::uppercase;
for (
const u_char* ptr = is_little_endian ? end - 1 : begin;
is_little_endian ? ptr >= begin : ptr < end;
is_little_endian ? --ptr : ++ptr
) {
std::cout << std::setfill('0') << std::setw(2) << static_cast<int>(*ptr);
}
std::cout << std::endl;
}

void PrintMemory(double /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
}
void PrintMemory(int num, bool is_little_endian = false) {
PrintMemory(reinterpret_cast<u_char*>(&num), sizeof(num), is_little_endian);
}

void PrintMemory(double num, bool is_little_endian = false) {
PrintMemory(reinterpret_cast<u_char*>(&num), sizeof(num), is_little_endian);
}
Loading