-
Notifications
You must be signed in to change notification settings - Fork 0
Control Task #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?
Control Task #5
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include <stdio.h> | ||
|
|
||
| void to2(char string[], int num); | ||
| int palindrom(char string[]); | ||
| int sizeOfString(char string[]); | ||
|
|
||
| void main() { | ||
| int n = 1; | ||
| scanf("%d", &n); | ||
| for (int i = 1; i <= n; i++) { | ||
| char string[200] = {' '}; | ||
| to2(string, i); | ||
|
|
||
| int res = palindrom(string); | ||
| if (res == 1) { | ||
| printf("%d\n", i); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void to2(char string[], int num) { | ||
|
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. Тут есть интересная попытка обмануть пользователя. Имя Если Ваша задача -- повалить программу, которая будет использовать Вашу библиотеку, то у Вас точно получится. |
||
| int index = 0; | ||
| while (num > 0) { | ||
| int ost = num % 2; | ||
| num = num / 2; | ||
| string[index] = (char) (ost); | ||
|
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. nit: обычно приведение форматируют так: А здесь даже гитхаб не понял, что происходит, и отключил подсветку. 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. Просто на всякий случай: если скастить, например, |
||
| index++; | ||
| } | ||
| string[index] = '\t'; | ||
|
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. Вы что ли рандомными символами терминируете строку? Конвенционально используется |
||
| } | ||
|
|
||
|
|
||
| int palindrom(char string[]) { | ||
| int res = 1; | ||
| int size = sizeOfString(string); | ||
|
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 < size; i++) { | ||
| if (string[i] != string[size-1-i]) { | ||
| res = 0; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return res; | ||
| } | ||
|
|
||
| int sizeOfString(char string[]) { | ||
| int size = 0; | ||
| while (string[size] != '\t') { | ||
| size++; | ||
| } | ||
|
|
||
| return size; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <stdio.h> | ||
|
|
||
| int getSum(int n); | ||
|
|
||
| void main() { | ||
| int arr[] = {2, 4, 6, 8, 10, 35}; | ||
| int size = sizeof(arr) / sizeof(int); | ||
|
|
||
| int mx = 0; | ||
|
|
||
| for (int i = 0; i < size; i++) { | ||
| int sm = getSum(arr[i]); | ||
| if (sm > mx) { | ||
| mx = sm; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| for (int i = 0; i < size; i++) { | ||
| int sm = getSum(arr[i]); | ||
| if (sm == mx) { | ||
| printf("%d\n", arr[i]); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
Comment on lines
+25
to
+29
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. Если верить HWProj, Вы сдали задачу за три минуты до дедлайна. За это время можно было хотя бы минимально привести код в порядок. |
||
| } | ||
|
|
||
| int getSum(int n) { | ||
| int sum = 0; | ||
| while (n != 0) { | ||
| sum = sum + n % 10; | ||
| n = n / 10; | ||
| } | ||
| return sum; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include <stdio.h> | ||
|
|
||
| int isSorted(int arr[], int size); | ||
| void swap(int arr[]); | ||
|
|
||
| void main() { | ||
| int arr[] = {2, 4, 6, 8, 10}; | ||
| int size = sizeof(arr) / sizeof(int); | ||
| printf("%d\n", isSorted(arr, size)); | ||
| for (int i = 0; i < size; i++) { | ||
| printf("%d ", arr[i]); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| int isSorted(int arr[], int size) { | ||
| for (int i = 0; i < size - 1; i++) { | ||
| if (arr[i] > arr[i+1]) { | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| return 1; | ||
| } | ||
|
|
||
| void swap(int arr[]) { | ||
|
|
||
| } |
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.