Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 11 additions & 6 deletions 1.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// Разверните строку. Указатель reverse_string должен
// указывать на развернутую строку.
#include <iostream>

char* string = "The string!";

int main()
{
char* reverse_string;

int len = strlen(string);
char* reverse_string = new char[len];
for(int i = 0 ; i < len; i++)
{
reverse_string[i] = string[len-1 - i];
}
reverse_string[len] = '\0';

Choose a reason for hiding this comment

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

ошибка - под len-ый элемент массива reverse_string не выделена память.

std::cout << reverse_string;
system("pause");
return 0;
}
}
13 changes: 10 additions & 3 deletions 2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Квадратная матрица разделена диагоналями на четыре сектора.
// Квадратная матрица разделена диагоналями на четыре сектора.
// Напишите функцию min_from_top_sector(), которая будет
// находить значение ячейки, минимальное для всех ячеек верхнего
// сектора, включая отрезки диагоналей, составляющие этот сектор.
Expand All @@ -10,14 +10,21 @@ typedef int Matrix[c_kM][c_kM];

int min_from_top_sector(Matrix& m)
{

int min = m[0][0];
for (int i = 0; i < c_kM/2 + c_kM % 2; i++)

Choose a reason for hiding this comment

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

вместо "c_kM % 2" можно просто "1"

for (int j = i; j < c_kM - i; j++)
{
if (m[i][j] <= min)

Choose a reason for hiding this comment

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

если m[i][j] == min, обновлять значение min бессмысленно

min = m[i][j];
}
return min;
}

int _tmain(int argc, _TCHAR* argv[])
{
Matrix matrix;

std::cout << min_from_top_sector(matrix) << std::endl;

return 0;
}
19 changes: 14 additions & 5 deletions 3.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Напишите функцию Add(), которая создает новый
// Напишите функцию Add(), которая создает новый
// объект List, инициализирует его входным значением
// value и добавляет его в конец списка l, полученного
// на вход. В функции main() создайте проинициализированный
// список, со значениями value равными: 1, 2, 3, 4 и 5.

struct List
{
int value;
Expand All @@ -14,10 +13,20 @@ struct List
// It should return pointer to the added List object.
List* Add(List* l, int value)
{

List *list = new List;
list->value = value;
list->next = NULL;
if (!l)
return list;
l->next = list;

Choose a reason for hiding this comment

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

что если пришел указатель на голову списка, где больше 1 элемента?
что если пришел NULL?

return list;
}

int main(int argc, char* argv[])
{
return 0;
}
List * list = new List;
list->value = 1;

Choose a reason for hiding this comment

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

в таком случае, зачем в функции проверка "if (!l)", если "пользователь" должен сам инициализировать первое значение?

for (int i = 1; i < 5; i++)
Add(list,i+1);

Choose a reason for hiding this comment

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

ты все время инициализируешь второй элемент списка.

return 0;
}