Moved kattis from Uni repo
This commit is contained in:
2
kattis/problems/old/aldursrodun/1.in
Normal file
2
kattis/problems/old/aldursrodun/1.in
Normal file
@ -0,0 +1,2 @@
|
||||
7
|
||||
5 10 7 15 14 3 2
|
2
kattis/problems/old/aldursrodun/2.in
Normal file
2
kattis/problems/old/aldursrodun/2.in
Normal file
@ -0,0 +1,2 @@
|
||||
3
|
||||
2 3 6
|
2
kattis/problems/old/aldursrodun/3.in
Normal file
2
kattis/problems/old/aldursrodun/3.in
Normal file
@ -0,0 +1,2 @@
|
||||
4
|
||||
2 5 7 10
|
BIN
kattis/problems/old/aldursrodun/aldursrodun
Executable file
BIN
kattis/problems/old/aldursrodun/aldursrodun
Executable file
Binary file not shown.
36
kattis/problems/old/aldursrodun/aldursrodun.c
Normal file
36
kattis/problems/old/aldursrodun/aldursrodun.c
Normal 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++) {
|
||||
|
||||
}
|
||||
}
|
55
kattis/problems/old/aldursrodun/main.c.orig
Normal file
55
kattis/problems/old/aldursrodun/main.c.orig
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user