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

char* string = "The string!";

#include <iostream>
char* string="The string!";;
int main()
{
char* reverse_string;

reverse_string=new char[strlen(string)+1];
int it(0);
for (int i=strlen(string)-1;i>=0;i--)
Copy link

Choose a reason for hiding this comment

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

I think, putting expressions which are to compute is not efficient, cuz it will compute every cycle,

int value=strlen(string)-1;
for(...)

Copy link

Choose a reason for hiding this comment

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

перший блок циклу for обчислюєтсья одноразово

{
reverse_string[it]=string[i];
it++;
}
reverse_string[it]='\0';
std::cout<<reverse_string<<std::endl;
system("pause");
delete[]reverse_string;
return 0;

Choose a reason for hiding this comment

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

не забываем чистить память

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

#include <iostream>
#include <iostream>

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

int min_from_top_sector(Matrix& m)
{
const int c_kM = 4;
typedef int Matrix[c_kM][c_kM];

int min_from_top_sector(Matrix& m)
{
double min;
min=m[0][0];
int indeks=(c_kM%2==0)?c_kM/2:c_kM/2+1;

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<indeks;i++)
{
for (int j=i;j<c_kM-i;j++)
{
if(m[i][j+i]<min)

Choose a reason for hiding this comment

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

при i == 0, j последний раз принимает значение j == c_kM-i == 5. потом в теле цикла ты обращаешься к элементу массива a[0][5+0] - выход за границы

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

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

for (int i=0;i<c_kM;i++)
{
for(int j=0;j<c_kM;j++)
cin>>matrix[i][j];
}
std::cout << min_from_top_sector(matrix) << std::endl;

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

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

List *newList=new List;
newList->value=value;
newList->next=NULL;
if(l)
{
while(l->next)
l=l->next;

l->next=newList;
return l;
}
else
return(newList);
}

int main(int argc, char* argv[])
{
List *_lst=new List;
_lst->value=1;
for(int i=1;i<5;i++)
_lst=Add(_lst,i);
return 0;
}
}