Moved kattis from Uni repo

This commit is contained in:
2023-12-01 13:35:13 +01:00
parent 28a6b807a3
commit aaa2c123b8
164 changed files with 3008 additions and 0 deletions

View File

@ -0,0 +1,2 @@
7
5 10 7 15 14 3 2

View File

@ -0,0 +1,2 @@
3
2 3 6

View File

@ -0,0 +1,2 @@
4
2 5 7 10

Binary file not shown.

View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
void print_array(int *arr, int n) {
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
int main(int argc, char **argv) {
int n;
scanf("%d", &n);
int arr[10];
for (int i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
}
for (int i=0; i<n; i++) {
for (int j=i; j<n; j++) {
if (arr[i] > arr[j]) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
}
print_array(arr, n);
int replaced[10];
for (int i=0; i<n; i++) {
}
}

View File

@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
int gcd(int a, int b) {
while (b) {
int temp = a % b;
a = b;
b = temp;
}
return a;
}
int compare(const void *a, const void *b) {
return (*(int*)a - *(int*)b);
}
int main() {
int n;
scanf("%d", &n);
int ages[n];
for (int i = 0; i < n; i++) {
scanf("%d", &ages[i]);
}
// Sort the ages in ascending order.
qsort(ages, n, sizeof(int), compare);
for (int i = 1; i < n; i++) {
if (gcd(ages[i], ages[i-1]) == 1) {
int swapped = 0;
for (int j = i + 1; j < n; j++) {
if (gcd(ages[j], ages[i-1]) > 1) {
// Swap ages[i] and ages[j].
int temp = ages[i];
ages[i] = ages[j];
ages[j] = temp;
swapped = 1;
break;
}
}
if (!swapped) {
printf("Neibb\n");
return 0;
}
}
}
for (int i = 0; i < n; i++) {
printf("%d ", ages[i]);
}
return 0;
}