-
Notifications
You must be signed in to change notification settings - Fork 7
My code #4
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?
My code #4
Changes from all commits
9cef507
fad215b
9236600
85b0634
951c7e0
1afb3f3
9d6fe56
02ff664
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,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--) | ||
| { | ||
| reverse_string[it]=string[i]; | ||
| it++; | ||
| } | ||
| reverse_string[it]='\0'; | ||
| std::cout<<reverse_string<<std::endl; | ||
| system("pause"); | ||
| delete[]reverse_string; | ||
| return 0; | ||
|
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. не забываем чистить память |
||
| } | ||
| } | ||
| 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; | ||
|
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. а можно красивее? |
||
| for (int i=0;i<indeks;i++) | ||
| { | ||
| for (int j=i;j<c_kM-i;j++) | ||
| { | ||
| if(m[i][j+i]<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. при 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; | ||
|
|
||
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.
I think, putting expressions which are to compute is not efficient, cuz it will compute every cycle,
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.
перший блок циклу for обчислюєтсья одноразово