Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
318cf97
add (solution): add addition, check_flags, lenght_lit, print_bits, qu…
VaryVA Nov 28, 2025
190ea20
add (solution): add check_flags task
VaryVA Nov 28, 2025
58fbe23
add (solution): add length_lit task
VaryVA Nov 28, 2025
3573ba1
add (solution): add print_bits task
VaryVA Nov 28, 2025
15ec4a4
add (solution): add quadratic task
VaryVA Nov 28, 2025
3fcc0bc
add (solution): add rms task
VaryVA Nov 28, 2025
841c809
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
VaryVA Dec 7, 2025
7e86b75
Merge branch 'psds-cpp:main' into main
VaryVA Dec 7, 2025
f174bae
add (solution): add func_array task
VaryVA Dec 8, 2025
2328946
Надо, я чего-то не того наделала (
VaryVA Dec 8, 2025
fc312f9
add (solution): add last_of_us task
VaryVA Dec 8, 2025
837fe51
add (solution): add little_big task
VaryVA Dec 8, 2025
6ea5c9f
add (solution): add longest task
VaryVA Dec 8, 2025
98e5d59
add (solution): add pretty_array task
VaryVA Dec 8, 2025
3a9a419
add (solution): add swap_ptr task
VaryVA Dec 8, 2025
97bb956
Merge branch 'psds-cpp:main' into main
VaryVA Feb 16, 2026
e66f289
add (solution): add cow string task
VaryVA Feb 16, 2026
ab6a48a
add (solution): add simple_vector task
VaryVA Feb 16, 2026
c51ee71
add (solution): add string_view task
VaryVA Feb 16, 2026
ad92d81
add (solution): add tracer task
VaryVA Feb 16, 2026
a4b2218
Merge branch 'psds-cpp:main' into main
VaryVA Feb 23, 2026
c0a7a6d
add (solution): add simple_list task
VaryVA Feb 23, 2026
7a02fa8
add (solution): add smart_ptr task
VaryVA Feb 23, 2026
802320f
add (solution): add unique_ptr task
VaryVA Feb 23, 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 (int64_t)a + (int64_t)b;
Copy link
Contributor

Choose a reason for hiding this comment

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

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

}
32 changes: 30 additions & 2 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 <iostream>

enum class CheckFlags : uint8_t {
NONE = 0,
Expand All @@ -14,5 +15,32 @@ 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 > static_cast<uint8_t>(CheckFlags::ALL)) {
return;
}

std::string result = "[";
bool first = true;

const std::pair<CheckFlags, const char*> flagNames[] = {
{CheckFlags::TIME, "TIME"},
{CheckFlags::DATE, "DATE"},
{CheckFlags::USER, "USER"},
{CheckFlags::CERT, "CERT"},
{CheckFlags::KEYS, "KEYS"},
{CheckFlags::DEST, "DEST"}
};
Copy link
Contributor

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] : flagNames) {
if (value & static_cast<uint8_t>(flag)) {
if (!first) result += ",";
result += name;
first = false;
}
}

result += "]";
std::cout << result;
}
104 changes: 104 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include <cmath>

constexpr double FOOT_TO_METER = 0.3048;
constexpr double INCH_TO_METER = 0.0254;
constexpr double METER_TO_FOOT = 1.0 / FOOT_TO_METER;
constexpr double METER_TO_INCH = 1.0 / INCH_TO_METER;
constexpr double CM_TO_METER = 0.01;
constexpr double METER_TO_CM = 100.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

лучше поместить в namespace, можно безымянный


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

constexpr double operator"" _ft_to_m(unsigned long long feet) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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

return static_cast<double>(feet) * FOOT_TO_METER;
}

constexpr double operator"" _ft_to_cm(long double feet) {
return static_cast<double>(feet) * FOOT_TO_METER * METER_TO_CM;
}

constexpr double operator"" _ft_to_cm(unsigned long long feet) {
return static_cast<double>(feet) * FOOT_TO_METER * METER_TO_CM;
}

constexpr double operator"" _ft_to_in(long double feet) {
return static_cast<double>(feet) * 12.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

12.0 это тоже magic value, которое не принято оставлять в коде

}

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

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

constexpr double operator"" _in_to_m(unsigned long long inches) {
return static_cast<double>(inches) * INCH_TO_METER;
}

constexpr double operator"" _in_to_cm(long double inches) {
return static_cast<double>(inches) * INCH_TO_METER * METER_TO_CM;
}

constexpr double operator"" _in_to_cm(unsigned long long inches) {
return static_cast<double>(inches) * INCH_TO_METER * METER_TO_CM;
}

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

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

constexpr double operator"" _m_to_ft(long double meters) {
return static_cast<double>(meters) * METER_TO_FOOT;
}

constexpr double operator"" _m_to_ft(unsigned long long meters) {
return static_cast<double>(meters) * METER_TO_FOOT;
}

constexpr double operator"" _m_to_in(long double meters) {
return static_cast<double>(meters) * METER_TO_INCH;
}

constexpr double operator"" _m_to_in(unsigned long long meters) {
return static_cast<double>(meters) * METER_TO_INCH;
}

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

constexpr double operator"" _m_to_cm(unsigned long long meters) {
return static_cast<double>(meters) * METER_TO_CM;
}

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

constexpr double operator"" _cm_to_m(unsigned long long centimeters) {
return static_cast<double>(centimeters) * CM_TO_METER;
}

constexpr double operator"" _cm_to_ft(long double centimeters) {
return static_cast<double>(centimeters) * CM_TO_METER * METER_TO_FOOT;
}

constexpr double operator"" _cm_to_ft(unsigned long long centimeters) {
return static_cast<double>(centimeters) * CM_TO_METER * METER_TO_FOOT;
}

constexpr double operator"" _cm_to_in(long double centimeters) {
return static_cast<double>(centimeters) * CM_TO_METER * METER_TO_INCH;
}

constexpr double operator"" _cm_to_in(unsigned long long centimeters) {
return static_cast<double>(centimeters) * CM_TO_METER * METER_TO_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 <iostream>

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

std::cout << "0b";

int total_bits = static_cast<int>(bytes) * 8;
for (int i = total_bits - 1; i >= 0; i--) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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

unsigned long long bit = (static_cast<unsigned long long>(value) >> i) & 1;
std::cout << bit;

if (i > 0 && i % 4 == 0) {
std::cout << "'";
}
}

std::cout << std::endl;
}
49 changes: 46 additions & 3 deletions 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
#include <iostream>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <stdexcept>


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";
Copy link
Contributor

Choose a reason for hiding this comment

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

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

}
}
else {
double x = -static_cast<double>(c) / b;
if (x == 0.0) x = 0.0;
std::cout << std::setprecision(6) << x;
}
return;
}

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

if (discriminant < 0) {
std::cout << "no solutions";
}
else if (discriminant == 0) {
double x = -static_cast<double>(b) / (2.0 * a);
if (x == 0.0) x = 0.0;
std::cout << std::setprecision(6) << x;
}
else {
double sqrt_d = std::sqrt(discriminant);
double x1 = (-static_cast<double>(b) - sqrt_d) / (2.0 * a);
double x2 = (-static_cast<double>(b) + sqrt_d) / (2.0 * a);

if (x1 == 0.0) x1 = 0.0;
if (x2 == 0.0) x2 = 0.0;

if (x1 > x2) {
std::swap(x1, x2);
}

std::cout << std::setprecision(6) << x1 << " " << x2;
}
}
20 changes: 15 additions & 5 deletions 01_week/tasks/rms/rms.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include <cstdef>
#include <stdexcept>

#include <cmath>
#include <cstddef>

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

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

double mean_of_squares = sum_of_squares / size;

return std::sqrt(mean_of_squares);
Copy link
Contributor

Choose a reason for hiding this comment

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

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

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

typedef double (*MathOperation)(double, double);
Copy link
Contributor

Choose a reason for hiding this comment

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

в С++ принято использовать using


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

double sum = 0.0;
for (size_t i = 0; i < size; ++i) sum += operations[i] ? operations[i](a, b) : 0.0;

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

typedef bool (*Predicate)(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, Predicate predicate) {
if (begin == nullptr || end == nullptr || begin > end || predicate == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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

return end;
}

for (const int* current = end - 1; current >= begin; --current) {
if (predicate(*current)) {
return current;
}
}

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

template<typename T>
void PrintMemoryImpl(T value, bool reverseBytes) {
unsigned char bytes[sizeof(T)];
std::memcpy(bytes, &value, sizeof(T));

std::cout << "0x";

if (reverseBytes) {
for (int i = sizeof(T) - 1; i >= 0; --i) {
std::cout << std::hex << std::setfill('0') << std::setw(2)
<< std::uppercase << static_cast<int>(bytes[i]);
}
} else {
for (size_t i = 0; i < sizeof(T); ++i) {
std::cout << std::hex << std::setfill('0') << std::setw(2)
<< std::uppercase << static_cast<int>(bytes[i]);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

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

}

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

void PrintMemory(int /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
void PrintMemory(int value, bool reverseBytes = false) {
PrintMemoryImpl(value, reverseBytes);
}

void PrintMemory(double /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
}
void PrintMemory(double value, bool reverseBytes = false) {
PrintMemoryImpl(value, reverseBytes);
}
29 changes: 27 additions & 2 deletions 02_week/tasks/longest/longest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
#include <stdexcept>

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

CharPtr best = begin;
CharPtr current = begin;
size_t bestLen = 1;
size_t currentLen = 1;

for (CharPtr p = begin + 1; p < end; ++p) {
(*p == *(p - 1)) ?
(currentLen++, (currentLen > bestLen) ? (void)(bestLen = currentLen, best = current) : (void)0) :
(void)(current = p, currentLen = 1);
}

count = bestLen;
return best;
}

char* FindLongestSubsequence(char* begin, char* end, size_t& count) {
return FindLongestSubsequenceImpl(begin, end, count);
Copy link
Contributor

Choose a reason for hiding this comment

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

зачем тогда писать Impl ? если можно сразу ссделать шаблон

}

/* return_type */ FindLongestSubsequence(/* ptr_type */ begin, /* ptr_type */ end, /* type */ count) {
throw std::runtime_error{"Not implemented"};
const char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) {
return FindLongestSubsequenceImpl(begin, end, count);
}
Loading