Skip to content
Open

- #2

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
66 changes: 61 additions & 5 deletions 1.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,65 @@
// ���������� ������. ��������� reverse_string ������ ��������� �� ����������� ������.
// Разверните строку. Указатель reverse_string должен
Copy link

Choose a reason for hiding this comment

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

думаю це варто випраивити, як і в інших файлах також

// указывать на развернутую строку.

#define USE_VERSION 1

static const char* str = "The string!";

#if (USE_VERSION == 1)

# include <stdio.h>
# include <string.h>
# include <stdlib.h>

void strreverse(char * aStr);

# define swap_char(left, right) { char _t = left; left = right; right = _t; }

# ifdef _MSC_VER
# define strdup _strdup
# endif

char* string = �The string!�;
int main()
{
char* reverse_string;
char* reverse_string = strdup(str); //strlen + alloc + memcpy

strreverse(reverse_string);

printf("%s\n", str);
printf("%s\n", reverse_string);

free(reverse_string);

return 0;
}

void strreverse(char * p)
{
char *q = p + strlen(p);
for(--q; p < q; ++p, --q)
swap_char(*p, *q);
}

#endif

#if (USE_VERSION == 2)

# include <iostream>
# include <algorithm>
// std::reverse
# include <string>

int main () {
std::string result(str);

std::reverse(result.begin(), result.end());

char* reverse_string = &result[0];

std::cout << "Original: " << str << std::endl;
std::cout << "Reversed: " << reverse_string << std::endl;

return 0;
}

return 0;
}
#endif
14 changes: 12 additions & 2 deletions 2.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
// ���������� ������� ��������� ����������� �� ������ �������. �������� ������� min_from_top_sector(), ������� ����� �������� �������� ������, ����������� ��� ���� ����� �������� �������, ������� ������� ����������, ������������ ���� ������.
// Квадратная матрица разделена диагоналями на четыре сектора.
// Напишите функцию min_from_top_sector(), которая будет находить
//значение ячейки, минимальное для всех ячеек верхнего сектора,
// включая отрезки диагоналей, составляющие этот сектор.

#include <iostream>

const int c_kM = 5;
typedef int Matrix[c_kM][c_kM];

int min_from_top_sector(Matrix& m)
{

int min = m[0][0];
for(size_t i = 0; i < (c_kM + 1) / 2; i++) {
for(size_t j = i; j < c_kM - i; j++) {
if (m[i][j] < min)
min = m[i][j];
}
}
}

int _tmain(int argc, _TCHAR* argv[])
Expand Down
51 changes: 47 additions & 4 deletions 3.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
// �������� ������� Add(), ������� ������� ����� ������ List, �������������� ��� ������� ��������� value � ��������� ��� � ����� ������ l, ����������� �� ����. � ������� main() �������� ��������������������� ������, �� ���������� value �������: 1, 2, 3, 4 � 5.
// Напишите функцию Add(), которая создает новый объект List, инициализирует
// его входным значением value и добавляет его в конец списка l, полученного на вход.
// В функции main() создайте проинициализированный список, со значениями value равными: 1, 2, 3, 4 и 5.

#include <iostream>

struct List
{
int value;
List* next;
int value;
List* next;

~List();

void printList() const;
};

// Add should create new List object, initialize it by value and add it to the end of the list.
// It should return pointer to the added List object.
List* Add(List* l, int value)
{
List *newElem = new List;
newElem->value = value;
newElem->next = NULL;

if (l) {
while (l->next)
l = l->next;

l->next = newElem;
}

return newElem;
}

int main(int argc, char* argv[])
{
return 0;
List *l, *tmpList;
size_t i;

l = Add(NULL, 1);
for (i = 2, tmpList = l; i < 6; i++)
tmpList = Add(tmpList, i);

l->printList();

delete l;

return 0;
}

List::~List()
{
delete next;
}

void List::printList() const
{
std::cout << "The list is:";
for (const List *iter = this; iter; iter = iter->next)
std::cout << " " << iter->value;
std::cout << std::endl;
}