-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a14935
commit e2f1640
Showing
9 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
|
||
void swap(int *a, int *b) { | ||
int temp = *a; | ||
*a = *b; | ||
*b = temp; | ||
} | ||
|
||
int partition(int arr[], int low, int high) { | ||
int pivot = arr[high]; | ||
int i = low; | ||
|
||
for (int j = low; j <= high; j++) { | ||
if (arr[j] < pivot) { | ||
swap(arr[i], arr[j]); | ||
i++; | ||
} | ||
} | ||
swap(arr[i + 1], arr[high]); | ||
return (i + 1); | ||
} | ||
|
||
void quick_sort(int arr[], int low, int high) { | ||
if (low < high) { | ||
int index = partition(arr, low, high); | ||
|
||
quick_sort(arr, low, index - 1); | ||
quick_sort(arr, index + 1, high); | ||
} | ||
} | ||
|
||
// check if b[] contains all elements of a[] | ||
bool is_subsequence(int a[], int size_a, int b[], int size_b) { | ||
quick_sort(a, 0, size_a); | ||
quick_sort(b, 0, size_b); | ||
|
||
int j = 0; | ||
for (int i = 0; i < size_a; i++) { | ||
if (a[i] < b[i]) | ||
return false; | ||
else if (a[i] > b[i]) | ||
i--; | ||
|
||
j++; | ||
|
||
if (j == size_b) | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
int main() { | ||
int size_a, size_b; | ||
if(!scanf("%d", &size_a)) printf("invalid value"); | ||
int* a = (int*)malloc((size_t)size_a * sizeof(int)); | ||
for (int i = 0; i < size_a; i++) { | ||
if(!scanf("%d", &a[i])) printf("invalid value"); | ||
} | ||
|
||
if(!scanf("%d", &size_b)) printf("invalid value"); | ||
int* b = (int*)malloc((size_t)size_b * sizeof(int)); | ||
for (int i = 0; i < size_b; i++) { | ||
if(!scanf("%d", &b[i])) printf("invalid value"); | ||
} | ||
|
||
printf(is_subsequence(a, size_a, b, size_b)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
// tab - all elements sorted in ascending order | ||
// a < b < c | ||
// c < a + b | ||
|
||
int trojki(int size, int tab[]) { | ||
|
||
} | ||
|
||
int main() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
5 | ||
1 2 3 4 5 | ||
5 | ||
5 4 3 2 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
6 | ||
1 2 3 4 5 6 | ||
5 | ||
5 4 3 2 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
6 | ||
1 2 3 4 5 6 | ||
7 | ||
-1 5 4 3 2 1 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 |