-
Notifications
You must be signed in to change notification settings - Fork 7
AmeksInterview #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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'; | ||
| std::cout << reverse_string; | ||
| system("pause"); | ||
| return 0; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Квадратная матрица разделена диагоналями на четыре сектора. | ||
| // Квадратная матрица разделена диагоналями на четыре сектора. | ||
| // Напишите функцию min_from_top_sector(), которая будет | ||
| // находить значение ячейки, минимальное для всех ячеек верхнего | ||
| // сектора, включая отрезки диагоналей, составляющие этот сектор. | ||
|
|
@@ -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++) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| 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; | ||
|
|
@@ -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; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. что если пришел указатель на голову списка, где больше 1 элемента? |
||
| return list; | ||
| } | ||
|
|
||
| int main(int argc, char* argv[]) | ||
| { | ||
| return 0; | ||
| } | ||
| List * list = new List; | ||
| list->value = 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ты все время инициализируешь второй элемент списка. |
||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ошибка - под len-ый элемент массива reverse_string не выделена память.