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,23 @@
#include <stdio.h>
#include <stdlib.h>
int reverse(int n) {
int reversed = 0;
while (n > 0) {
reversed = reversed * 10 + n % 10;
n /= 10;
}
return reversed;
}
int main(int argc, char **argv) {
int a, b;
scanf("%d %d", &a, &b);
a = reverse(a);
b = reverse(b);
printf("%d\n", a > b ? a : b);
return 0;
}

View File

@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int powerOfTen(int a) {
int result = 10;
for (int i=0; i<a; i++) {
result *= 10;
}
return result;
}
void findLarger(int a, int b) {
for (int i=0; i<3; i++) {
if (a%10 > b%10) {
printf("%d", a%10);
} else {
printf("%d", b%10);
}
a /= 10;
b /=10;
}
printf("\n");
}
// FIX: Reverse number
int main(int argc, char **argv) {
int a, b;
scanf("%d %d", &a, &b);
findLarger(a, b);
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,2 @@
12000 3000 5
400 25 200 80 500

View File

@ -0,0 +1,2 @@
10000 4000 7
110 10 20 10 5 3 5

View File

@ -0,0 +1,16 @@
#include <stdint.h>
#include <stdio.h>
int main(int argc, char **argv) {
int g, t, n;
scanf("%d %d %d", &g, &t, &n);
int sum = 0;
for (int i=0; i<n; i++) {
int a;
scanf("%d", &a);
sum += a;
}
int lol = (g-t) * 9/10;
printf("%d\n", lol-sum);
return 0;
}

View File

@ -0,0 +1,11 @@
#include <stdint.h>
#include <stdio.h>
int main(int argc, char **argv) {
int g, t, n;
scanf("%d %d %d", &g, &t, &n);
int sum = 0;
for (int i=0; i<n; i++) sum++;
printf("%d\n", g-t-sum);
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
return 0;
}

View File

@ -0,0 +1 @@
iLnLnLeLb

View File

@ -0,0 +1 @@
arnarLLLBBun

View File

@ -0,0 +1 @@
password123

View File

@ -0,0 +1,60 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000000
int transform(char *src, int len, char *dst) {
// Traverse the string
int i = len;
int j = 0;
while (i > 0) {
// printf("%c\n", src[i]);
// If we encounter a backspace, we need to remove the last character
// from the destination string
if (src[i] == 'B') {
if (j > 0) {
j--;
}
} else if (src[i] == 'L') {
// If we encounter a left button, we have to move back once
if (j > 0) {
j--;
}
} else if (src[i] == 'R') {
// If we encounter a right button, we have to move forward once
if (j < len) {
j++;
}
}
else {
// Otherwise, we add the character to the destination string
dst[j] = src[i];
j++;
}
i--;
}
return j;
}
void printStr(char *s, int len) {
for (int i = 0; i < len; ++i) {
printf("%c", s[i]);
}
printf("\n");
}
int main(int argc, char **argv) {
char s[MAX];
scanf("%s", s);
int len = strlen(s);
printf("%d\n", len);
char corrected[MAX];
int newLen = transform(s, len, corrected);
printf("%d\n", newLen);
printStr(corrected, newLen);
return 0;
}

View File

@ -0,0 +1,58 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000000
int transform(char *src, int len, char *dst) {
// Traverse the string
int i = 0;
int j = 0;
while (i < len) {
// If we encounter a backspace, we need to remove the last character
// from the destination string
if (src[i] == 'B') {
if (j > 0) {
j--;
}
} else if (src[i] == 'L') {
// If we encounter a left button, we have to move back once
if (j > 0) {
j--;
}
} else if (src[i] == 'R') {
// If we encounter a right button, we have to move forward once
if (j < len) {
j++;
}
}
else {
// Otherwise, we add the character to the destination string
dst[j] = src[i];
j++;
}
i++;
}
return j;
}
void printStr(char *s, int len) {
for (int i = 0; i < len; ++i) {
printf("%c", s[i]);
}
printf("\n");
}
int main(int argc, char **argv) {
char s[MAX];
scanf("%s", s);
int len = strlen(s);
char corrected[MAX];
int newLen = transform(s, len, corrected);
printf("%d\n", newLen);
printStr(corrected, newLen);
return 0;
}

View File

@ -0,0 +1,22 @@
string = input()
string_list = []
cursor = 0
for char in string:
# If 'L' found in string, we move the cursor to the left
if char == 'L':
if cursor > 0:
cursor -= 1
# If 'R' found in string, we move the cursor to the right
elif char == 'R':
if cursor < len(string):
cursor += 1
# If 'B' found in string, we delete the character to the left of the cursor
elif char == 'B':
del string_list[cursor - 1]
cursor -= 1
# If any other character found in string, we insert it to the left of the cursor
else:
string_list.insert(cursor, char)
cursor += 1
# Print only the new string, without the initial one
print(''.join(string_list))

Binary file not shown.

View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int n, h, v;
scanf("%d %d %d", &n, &h, &v);
int max_h = h > n - h ? h : n - h;
int max_v = v > n - v ? v : n - v;
printf("%d\n", max_h * max_v * 4);
return 0;
}

View File

@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int n, k;
scanf("%d %d", &n, &k);
int sum = 0;
for (int i = 0; i < k; ++i) {
int x;
scanf("%d", &x);
sum += x;
}
int min = sum - (n - k) * 3;
int max = sum + (n - k) * 3;
printf("%.6f %.6f\n", min / (double)n, max / (double)n);
return 0;
}

View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int pa, ka, pb, kb, n;
scanf("%d %d %d %d %d", &pa, &ka, &pb, &kb, &n);
int tripsA = 0, tripsB = 0;
int totalCost = 0;
int costA = pa/ka;
int costB = pb/kb;
while (n > 0) {
if (costA < costB && ka < n) {
tripsA++;
totalCost += pa;
} else {
tripsB++;
totalCost += pb;
}
n--;
}
printf("%d %d %d\n", tripsA, tripsB, totalCost);
return 0;
}

View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int pa, ka, pb, kb, n;
scanf("%d %d %d %d %d", &pa, &ka, &pb, &kb, &n);
int tripsA = 0, tripsB = 0;
int totalCost = 0;
int costA = pa/ka;
int costB = pb/kb;
while (n > 0) {
if (pa < pb && ka < n) {
tripsA++;
totalCost += pa;
} else {
tripsB++;
totalCost += pb;
}
n--;
}
printf("%d %d %d\n", tripsA, tripsB, pa+pb);
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX 21
int main(int argc, char **argv) {
int n;
scanf("%d", &n);
int matrix[MAX][MAX];
int i, j, k;
while (n != -1) {
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &matrix[i][j]);
}
}
int weak[MAX];
for (i = 0; i < n; i++) {
weak[i] = 1;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
for (k = 0; k < n; k++) {
if (matrix[i][j] && matrix[j][k] && matrix[k][i]) {
weak[i] = 0;
weak[j] = 0;
weak[k] = 0;
}
}
}
}
for (i = 0; i < n; i++) {
if (weak[i]) {
printf("%d ", i);
}
}
printf("\n");
scanf("%d", &n);
}
}

View File

@ -0,0 +1,11 @@
#include <stdint.h>
#include <stdio.h>
#define MIN(x,y) x>y ? 1 : 0
int main(int argc, char **argv) {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", MIN(a, b));
return 0;
}

View File

@ -0,0 +1,11 @@
#include <stdint.h>
#include <stdio.h>
#define MIN(x,y) x>y ? 1 : 0
int main(int argc, char **argv) {
int a,b;
scanf("%d %d");
printf("%d\n", MIN(a,b));
return 0;
}

Binary file not shown.