Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
52d6984
Задание для первой недели
lefff123 Nov 28, 2025
d1f9351
поправил переполнение при сложении двух чисел
lefff123 Nov 28, 2025
2f614d2
поправил некорректное использование std::sqrt и заданну библиотеку cs…
lefff123 Nov 28, 2025
9e23d9c
добавил проверку на нулевой указатель
lefff123 Nov 28, 2025
ac60374
поправил задание check_flags
lefff123 Nov 28, 2025
32b370b
убрал вывод none в случае передачи нулевой маски
lefff123 Nov 28, 2025
56b2de9
поправил length literals
lefff123 Nov 28, 2025
f9c2325
поправил точность вычисления в length_literals
lefff123 Nov 28, 2025
76a91bb
поправил неправильный отсчет при замене символов
lefff123 Nov 28, 2025
6377cfa
попробуем вот так
lefff123 Nov 28, 2025
fd55daa
поправил лишнюю ;
lefff123 Nov 28, 2025
2a914a2
поправил ошибки в обработке пробельных символов
lefff123 Nov 28, 2025
14d2b04
попробуем так
lefff123 Nov 28, 2025
966fe7b
попробуем еще раз
lefff123 Nov 28, 2025
ffe522c
еще раз
lefff123 Nov 28, 2025
b8514da
надеюсь, финальная версия
lefff123 Nov 28, 2025
013b80d
add (solution): add func_array task
lefff123 Dec 9, 2025
fd67092
add (solution): add last_of_us task
lefff123 Dec 9, 2025
69d0d85
add (solution): add little_big task
lefff123 Dec 9, 2025
43ece52
add (solution): add longest task
lefff123 Dec 9, 2025
fe7df69
add (solution): add pretty_array task
lefff123 Dec 9, 2025
9533584
add (solution): add swap_ptr task
lefff123 Dec 9, 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
3 changes: 2 additions & 1 deletion 01_week/tasks/addition/addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@


int64_t Addition(int a, int b) {
throw std::runtime_error{"Not implemented"};
int64_t c=static_cast<int64_t>(a)+static_cast<int64_t>(b);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

return c;
}
86 changes: 84 additions & 2 deletions 01_week/tasks/char_changer/char_changer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,89 @@
#include <cstddef>
#include <stdexcept>
#include <stdlib.h>
#include <string.h>

size_t CharChanger(char array[], size_t size, char delimiter = ' ')
{
char array_fin[size]={};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

пробелы


size_t CharChanger(char array[], size_t size, char delimiter = ' ') {
throw std::runtime_error{"Not implemented"};
size_t temp_ptr = 0; // переменная для хранения текущего положения данных в массиве

for (size_t i = 0; i < size-1; ++i)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

пробелы

{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

лишняя пустая строка

if (isalnum(array[i]))
{ // если это буква-цифра
if (isalpha(array[i]))
{ // если это буква
size_t temp = 1;
if (i + 1 < size)
while (temp + i < size && array[i] == array[i + temp])
++temp;
array_fin[temp_ptr] = array[i];
if (islower(array[i]))
{ // если она низкая, делаем ее высокой
array_fin[temp_ptr] = toupper(array[i]);
}
++temp_ptr; // счетчик на конец преобразованного массива +1
i += temp - 1; // смещаем счетчик рабочий

if (temp > 1)
{ // если у нас много повторяющихся букоф
temp >= 10 ? (array_fin[temp_ptr] = '0') : (array_fin[temp_ptr] = '0' + temp); // ставим число повторений, либо 0, если повторений больше 10
++temp_ptr; // увеличиваем рабочий счетчик
}
}
else
{ // обрабатываем цифры
size_t temp = 1;
while (temp + i < size && array[i] == array[i + temp])
++temp;
array_fin[temp_ptr] = '*';
++temp_ptr;
i += temp - 1;
if (temp > 1)
{ // если у нас много повторяющихся цифр
temp >= 10 ? (array_fin[temp_ptr] = '0') : (array_fin[temp_ptr] = '0' + temp); // ставим число повторений, либо 0, если повторений больше 10
++temp_ptr; // увеличиваем рабочий счетчик
}
}
}
else
{
if (array[i] != ' ')
{
// обрабатываем символы..
size_t temp = 1;
while (temp + i < size && array[i] == array[i + temp])
++temp;
array_fin[temp_ptr] = '_';
++temp_ptr;
i += temp - 1;
if (temp > 1)
{ // если у нас много повторяющихся цифр
temp >= 10 ? (array_fin[temp_ptr] = '0') : (array_fin[temp_ptr] = '0' + temp); // ставим число повторений, либо 0, если повторений больше 10
++temp_ptr; // увеличиваем рабочий счетчик
}
}
else
{ //...если это не пробел. если пробел, то все ок, меняем:
size_t temp = 1;
while (temp + i < size && array[i] == array[i + temp])
++temp;
i += temp-1;
array_fin[temp_ptr] = delimiter;
++temp_ptr;
}
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

очень много лишнего кода и дублирование

for (size_t i = temp_ptr; i < size; ++i)
{
array[i] = '\0'; // зануляем все оставшееся место в памяти
}

strncpy(array, array_fin, size);

return temp_ptr;
}

64 changes: 63 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 @@ -13,6 +14,67 @@ enum class CheckFlags : uint8_t {
ALL = TIME | DATE | USER | CERT | KEYS | DEST
};


// побитовое сравнение каждого флага и переданного числа. сравниваем,, приводя все к 8-ми битному инту
// пробовал сделать через switch, не получилось. удивился, что к CheckFlags обращаемся как к пространству имен


void PrintCheckFlags(CheckFlags flags) {
throw std::runtime_error{"Not implemented"};
uint8_t value = static_cast<uint8_t>(flags);

if (value > 0b00111111) { // Если установлены биты вне диапазона 0-5
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

magic value для этого есть ALL

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

bool first=true;

std::cout<<'[';

if (static_cast<uint8_t>(flags)&static_cast<u_int8_t>(CheckFlags::TIME))
{
std::cout<<"TIME";
first=false;
}

if (static_cast<uint8_t>(flags)&static_cast<u_int8_t>(CheckFlags::DATE))
{
if (!first) std::cout<<",";
first = false;
std::cout<<"DATE";
}

if (static_cast<uint8_t>(flags)&static_cast<u_int8_t>(CheckFlags::USER))
{
if (!first) std::cout<<",";
first = false;
std::cout<<"USER";
}

if (static_cast<uint8_t>(flags)&static_cast<u_int8_t>(CheckFlags::CERT))
{
if (!first) std::cout<<",";
first = false;
std::cout<<"CERT";
}

if (static_cast<uint8_t>(flags)&static_cast<u_int8_t>(CheckFlags::KEYS))
{
if (!first) std::cout<<",";
first = false;
std::cout<<"KEYS";
}

if (static_cast<uint8_t>(flags)&static_cast<u_int8_t>(CheckFlags::DEST))
{
if (!first) std::cout<<",";
first = false;
std::cout<<"DEST";
}

std::cout<<']';




Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

милльон пустых строк

}
41 changes: 41 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
constexpr long double operator""_m_to_cm(long double value){
return value *100.00L;
};
constexpr long double operator""_cm_to_m(long double value){
return value * 0.01L;
};

constexpr long double operator""_m_to_ft(long double value) {
return value *3.280839895013123L;
};

constexpr long double operator""_m_to_in(long double value) {
return value *39.37007874015748031496062992L;
};
constexpr long double operator""_in_to_m(long double value) {
return value*0.0254L;
};
constexpr long double operator""_ft_to_m(long double value) {
return value *0.3048L;
};
constexpr long double operator""_ft_to_in(long double value) {
return value *12.0L;
};

constexpr long double operator""_in_to_ft(long double value) {
return value /12.0L;
};

constexpr long double operator""_cm_to_ft(long double value) {
return value *0.03280839895013123359580052493L;
};

constexpr long double operator""_cm_to_in(long double value) {
return value *0.39370078740157480314L;
};
constexpr long double operator""_in_to_cm(long double value) {
return value* 2.54L;
};
constexpr long double operator""_ft_to_cm(long double value) {
return value *30.48L;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Очень много magic value и лишних литералов, все нужно выразить через константы которым дать осмысленные имена, например для 12, 2.54 и 30.48, достаточно для преобразований

};
23 changes: 21 additions & 2 deletions 01_week/tasks/print_bits/print_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
#include <cstddef>
#include <stdexcept>
#include <iostream>

void PrintBits(long long value, size_t bytes)
{
if (bytes <= 8 && bytes > 0){
char counter = 0;

void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
std::cout << "0b";

for (int i = 8*bytes - 1; i >= 0; --i)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

пробелы

{
if (counter % 4 == 0 && counter)
{
std::cout << '\'';
counter = 0;
}
std::cout << ((value >> i) & 1);
++counter;
}

std::cout << '\n';
}

}
48 changes: 46 additions & 2 deletions 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <cmath>


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

Choose a reason for hiding this comment

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

лучше не делать такую вложенность, а объединить соответствующие условия для отдельных случаев и сделать короткие ветви с выводом нужного текста и выхода из функции

} else {
std::cout << "no solutions";
}
} else {
std::cout << static_cast<double>(-c) / static_cast<double>(b);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

лишний каст, достаточно сделать один

}
return;
}

double discr = b * b - 4 * a * c;

if (discr)
{
if (discr > 0)
{
double solution1 = 0;
double solution2 = 0;

solution1 = (-b + std::sqrt(discr)) / (a * 2.);
solution2 = (-b - std::sqrt(discr)) / (a * 2.);

if (solution1 > solution2)
std::swap(solution1, solution2);

std::cout << std::setprecision(6) << solution1 << ' ' << solution2;
}
else
{
std::cout << "no solutions";

}
}
else
{
std::cout << std::setprecision(6) << (-b - std::sqrt(discr)) / (2.0 * a);

}
Copy link
Copy Markdown
Collaborator

@18thday 18thday Jan 12, 2026

Choose a reason for hiding this comment

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

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

}
18 changes: 14 additions & 4 deletions 01_week/tasks/rms/rms.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include <cstdef>
#include <cstdint>
#include <stdexcept>
#include <cmath>


double CalculateRMS(double values[], size_t size) {
throw std::runtime_error{"Not implemented"};
double CalculateRMS(double values[], size_t size)
{
if (!size || values == nullptr){
return 0.;
}
long double sum = 0;
for (size_t i = 0; i < size; ++i)
{
sum += values[i]*values[i];
}

return static_cast<double>(std::sqrt(sum/static_cast<double> (size)));
Copy link
Copy Markdown
Collaborator

@18thday 18thday Jan 12, 2026

Choose a reason for hiding this comment

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

лишние пробелы и недостающие пробелы

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

double ApplyOperations(double a, double b, double (*func[])(double x, double y), size_t size)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Задачи второй и третьей недели прокоментированы через ПР в основной репозиторий

{
long double sum = 0.;
if (func)
{
for (size_t i = 0; i < size; ++i)
{
if (*(func+i))
sum += func[i](a, b);
}
}

return sum;
}
17 changes: 17 additions & 0 deletions 02_week/tasks/last_of_us/last_of_us.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdexcept>

const int* FindLastElement(const int* begin, const int* end, bool predicate(int x))
{
if (predicate && begin && end)
{
size_t size = end - begin;
for (long i = size-1; i>=0; --i)
{
if (predicate(begin[i]))
{
return (begin + i);
}
}
}
return end;
}
Loading
Loading