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
12 changes: 10 additions & 2 deletions 1.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
// Разверните строку. Указатель reverse_string должен
// указывать на развернутую строку.

#include <cstring>
char* string = "The string!";

int main()
{
char* reverse_string;

int Len = strlen(string);
reverse_string = new char[Len + 1];
reverse_string[Len] = '\0'; // ending 0
for(int beg = 0, end = Len - 1; beg <= end; beg++, end--)
{
reverse_string[beg] = string[end];
reverse_string[end] = string[beg];
}
delete [] reverse_string;
return 0;
}
10 changes: 9 additions & 1 deletion 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ typedef int Matrix[c_kM][c_kM];

int min_from_top_sector(Matrix& m)
{

int min = m[0][0];
int middle = c_kM / 2 + 1;

Choose a reason for hiding this comment

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

а если c_kM четное?

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Согласен

for(int i = 0; i < middle; i++)
for(int j = i; j < c_kM - i; j++)
{
if(min > m[i][j])
min = m[i][j];
}
return min;
}

int _tmain(int argc, _TCHAR* argv[])
Expand Down
26 changes: 25 additions & 1 deletion 3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,34 @@ struct List
// It should return pointer to the added List object.
List* Add(List* l, int value)
{

List * new_last = new List();
new_last->next = nullptr;
new_last->value = value;
if(!l) // if empty
return new_last;
while(l->next) // find the last element
l = l->next;
l->next = new_last;
return new_last;
Copy link

Choose a reason for hiding this comment

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

новий_останній, як же тут пахне копіпастом=)

Copy link
Author

Choose a reason for hiding this comment

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

Поясніть чи підтвердіть, будь ласка, вашу думку.

Copy link

Choose a reason for hiding this comment

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

а, до мене нарешті дійла ваша думка. Я подумав, що мало бути new_list. це було б очевидно для мене (new_list = new List...)

}

void FreeList(List* head)
{
if(!head)
return;
FreeList(head->next);
delete head;
head = nullptr;
}
int main(int argc, char* argv[])
{
const int N = 6;
List * l = Add(nullptr, 1);
for(int i = 2; i < N; i++)
{
Add(l, i);
}
FreeList(l);

return 0;
}