Moved kattis from Uni repo
This commit is contained in:
23
kattis/problems/01_11_23/filip/main.c
Normal file
23
kattis/problems/01_11_23/filip/main.c
Normal 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;
|
||||
}
|
34
kattis/problems/01_11_23/filip/main.c.orig
Normal file
34
kattis/problems/01_11_23/filip/main.c.orig
Normal 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;
|
||||
}
|
BIN
kattis/problems/01_11_23/filip/program
Executable file
BIN
kattis/problems/01_11_23/filip/program
Executable file
Binary file not shown.
2
kattis/problems/01_11_23/gcvwr/1.in
Normal file
2
kattis/problems/01_11_23/gcvwr/1.in
Normal file
@ -0,0 +1,2 @@
|
||||
12000 3000 5
|
||||
400 25 200 80 500
|
2
kattis/problems/01_11_23/gcvwr/2.in
Normal file
2
kattis/problems/01_11_23/gcvwr/2.in
Normal file
@ -0,0 +1,2 @@
|
||||
10000 4000 7
|
||||
110 10 20 10 5 3 5
|
16
kattis/problems/01_11_23/gcvwr/main.c
Normal file
16
kattis/problems/01_11_23/gcvwr/main.c
Normal 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;
|
||||
}
|
11
kattis/problems/01_11_23/gcvwr/main.c.orig
Normal file
11
kattis/problems/01_11_23/gcvwr/main.c.orig
Normal 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;
|
||||
}
|
BIN
kattis/problems/01_11_23/gcvwr/program
Executable file
BIN
kattis/problems/01_11_23/gcvwr/program
Executable file
Binary file not shown.
9
kattis/problems/01_11_23/julmust/main.c
Normal file
9
kattis/problems/01_11_23/julmust/main.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
1
kattis/problems/01_11_23/keystrokes/1.in
Normal file
1
kattis/problems/01_11_23/keystrokes/1.in
Normal file
@ -0,0 +1 @@
|
||||
iLnLnLeLb
|
1
kattis/problems/01_11_23/keystrokes/2.in
Normal file
1
kattis/problems/01_11_23/keystrokes/2.in
Normal file
@ -0,0 +1 @@
|
||||
arnarLLLBBun
|
1
kattis/problems/01_11_23/keystrokes/3.in
Normal file
1
kattis/problems/01_11_23/keystrokes/3.in
Normal file
@ -0,0 +1 @@
|
||||
password123
|
60
kattis/problems/01_11_23/keystrokes/main.c
Normal file
60
kattis/problems/01_11_23/keystrokes/main.c
Normal 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;
|
||||
}
|
58
kattis/problems/01_11_23/keystrokes/main.c.orig
Normal file
58
kattis/problems/01_11_23/keystrokes/main.c.orig
Normal 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;
|
||||
}
|
22
kattis/problems/01_11_23/keystrokes/main.py
Normal file
22
kattis/problems/01_11_23/keystrokes/main.py
Normal 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))
|
BIN
kattis/problems/01_11_23/keystrokes/program
Executable file
BIN
kattis/problems/01_11_23/keystrokes/program
Executable file
Binary file not shown.
13
kattis/problems/01_11_23/pieceofcake/main.c
Normal file
13
kattis/problems/01_11_23/pieceofcake/main.c
Normal 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;
|
||||
}
|
20
kattis/problems/01_11_23/ratingproblems/main.c
Normal file
20
kattis/problems/01_11_23/ratingproblems/main.c
Normal 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;
|
||||
}
|
25
kattis/problems/01_11_23/refrigerator/main.c
Normal file
25
kattis/problems/01_11_23/refrigerator/main.c
Normal 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;
|
||||
}
|
26
kattis/problems/01_11_23/refrigerator/main.c.orig
Normal file
26
kattis/problems/01_11_23/refrigerator/main.c.orig
Normal 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;
|
||||
}
|
BIN
kattis/problems/01_11_23/refrigerator/program
Executable file
BIN
kattis/problems/01_11_23/refrigerator/program
Executable file
Binary file not shown.
40
kattis/problems/01_11_23/weakvertices/main.c
Normal file
40
kattis/problems/01_11_23/weakvertices/main.c
Normal 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);
|
||||
}
|
||||
}
|
11
kattis/problems/01_11_23/whichisgreater/main.c
Normal file
11
kattis/problems/01_11_23/whichisgreater/main.c
Normal 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;
|
||||
}
|
11
kattis/problems/01_11_23/whichisgreater/main.c.orig
Normal file
11
kattis/problems/01_11_23/whichisgreater/main.c.orig
Normal 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;
|
||||
}
|
BIN
kattis/problems/01_11_23/whichisgreater/program
Executable file
BIN
kattis/problems/01_11_23/whichisgreater/program
Executable file
Binary file not shown.
Reference in New Issue
Block a user