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;
}

View File

@ -0,0 +1,5 @@
4
9 0123456789 oF8
Foo oF8 0123456789
13 0123456789abcdef 01
CODE O!CDE? A?JM!.

View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
int t;
scanf("%d", &t);
int printed = 0;
for (int i=0; i<t; i++) {
// Newlines
if(printed) printf("\n");
else printed = 1;
char word[100];
char src[95];
char dst[95];
scanf("%s %s %s", word, src, dst);
int idx = 0;
for (int i=0; i<strlen(src); i++) {
for(int j=0; j<strlen(word); j++) {
if (src[i] == word[j]) {
for (int k=0; k<i; k);
}
}
}
// Print case number
printf("Case #%d: ", i);
// TODO: Print the translation
}
return 0;
}

View File

@ -0,0 +1,27 @@
def src_to_int(code, language):
length = len(language)
result = 0
n = 0
m = {language[x]:x for x in range(length)}
for i in reversed(code):
s += m[i] * length ** n
n += 1
return s
def int_to_src(number, language):
length = len(language)
result = ""
n = 0
m = {x:language[x] for x in range(length)}
while num > 0:
def main():
cases:int = int(input())
for i in range(cases):
word, src, dst = input().split(" ")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,9 @@
2 S
TH
9C
KS
QS
JS
TD
AD
JH

View File

@ -0,0 +1,17 @@
4 H
AH
KH
QH
JH
TH
9H
8H
7H
AS
KS
QS
JS
TS
9S
8S
7S

View File

@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int hands;
char dominant;
scanf("%d %c", &hands, &dominant);
int points = 0;
for (int i=0; i<hands*4; i++) {
char card, suit;
scanf(" %c%c", &card, &suit); // <--- The god damn space in front!!
switch (card) {
case 'A':
points += 11;
break;
case 'K':
points += 4;
break;
case 'Q':
points += 3;
break;
case 'J':
if (dominant == suit) {
points += 20;
break;
}
points += 2;
break;
case 'T':
points += 10;
break;
case '9':
if (dominant == suit) {
points += 14;
break;
}
default:
points += 0;
break;
}
}
printf("%d\n", points);
}

View File

@ -0,0 +1,14 @@
3 3
1
u 1
4 5
2
u 3
r 4
10 10
4
r 30
d 30
l 25
u 5
0 0

View File

@ -0,0 +1,71 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
void move(char d, int s, int w, int l, int *rx, int *ry, int *x, int *y) {
if (d == 'u') {
*ry += s;
if (*y + s < l) {
*y += s;
} else {
*y = l-1;
}
} else if (d == 'd') {
*ry -= s;
if (*y - s >= 0) {
*y -= s;
} else {
*y = 0;
// WOW. WOW. WOW. WOW. WOW.
}
} else if (d == 'l') {
*rx -= s;
if (*x - s >= 0) {
*x -= s;
} else if (*x - s < 0) {
*x = 0;
}
} else if (d == 'r') {
*rx += s;
if (*x + s < w) {
*x += s;
} else {
*x = w-1;
}
}
}
int main(int argc, char **argv) {
int w = -1, l = -1;
int printed = 0;
while (1) {
// Handle room size
scanf("%d %d", &w, &l);
if (w == 0 && l == 0) {
return 0;
}
// Initialize actual and robot coords
int x = 0, y = 0, rx = 0, ry = 0;
int moves;
// Do moves
scanf("%d", &moves);
for (int i=0; i<moves; i++) {
// Take direction and steps(in meters or whatever)
char d;
int s;
scanf(" %c %d", &d, &s);
// Dear C, I hope you fucking die in a fire. What the fuck is the difference between "%c" and " %c" you pretentious ancient piece of shit. :P
// P.S. Why the fuck is my code not working?1/1/?!?1/
// Move
move(d, s, w, l, &rx, &ry, &x, &y);
}
if (printed) {
printf("\n");
} else {
printed = 1;
}
printf("Robot thinks %d %d\nActually at %d %d\n", rx, ry, x, y);
}
return 0;
}

View File

@ -0,0 +1,72 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
void move(char d, int s, int w, int l, int *rx, int *ry, int *x, int *y) {
if (d == 'u') {
*ry += s;
if (*y + s < l) {
*y += s;
} else {
*y = l-1;
}
} else if (d == 'd') {
*ry -= s;
if (*y - s >= 0) {
*y -= s;
} else {
*x = 0;
}
} else if (d == 'l') {
*rx -= s;
if (*x - s >= 0) {
*x -= s;
} else if (*x - s < 0) {
*x = 0;
}
} else if (d == 'r') {
*rx += s;
if (*x + s < w) {
*x += s;
} else {
*x = w-1;
}
}
}
int main(int argc, char **argv) {
int w = -1, l = -1;
int printed = 0;
while (1) {
// Handle room size
scanf("%d %d", &w, &l);
if (w == 0 && l == 0) {
return 0;
}
// Initialize actual and robot coords
int x = 0, y = 0, rx = 0, ry = 0;
int moves;
// Do moves
scanf("%d", &moves);
for (int i=0; i<moves; i++) {
// Take direction and steps(in meters or whatever)
char d;
int s;
scanf(" %c %d", &d, &s);
// Dear C, I hope you fucking die in a fire. What the fuck is the difference between "%c" and " %c" you pretentious ancient piece of shit. :P
// P.S. Why the fuck is my code not working?1/1/?!?1/
// Move
move(d, s, w, l, &rx, &ry, &x, &y);
}
if (printed) {
printf("\n");
} else {
printed = 1;
}
printf("Robot thinks %d %d\nActually at %d %d\n", rx, ry, x, y);
}
return 0;
}

View File

@ -0,0 +1,13 @@
2
7
saskatoon
toronto
winnipeg
toronto
vancouver
saskatoon
toronto
3
edmonton
edmonton
edmonton

View File

@ -0,0 +1,10 @@
test_cases = int(input())
for case in range(test_cases):
destinations = []
trips = int(input())
for t in range(trips):
trip = str(input())
if trip not in destinations:
destinations.append(trip)
print(len(destinations))

View File

@ -0,0 +1,5 @@
7 4
#######
#P.GTG#
#..TGG#
#######

View File

@ -0,0 +1,7 @@
8 6
########
#...GTG#
#..PG.G#
#...G#G#
#..TG.G#
########

View File

@ -0,0 +1,74 @@
0
0023.0
3.
9.8__auto_type
// Avoid visiting visited nodes(endless loop occurs)
if (visited[my][mx]) {
return ;
}
visited[my][mx] = true;
31 7
// Stop if drafty or wall. Increment counter if gold is found.
if (c == '#') {
return ;
}
if(c == 'T'){
return ;
= 0
// printf("x: %d, y: %d, c: %c\n", mx, my, c);
if (c == 'G') {
counter++;
}
// Move (as long as we're not stepping out of bounds)
if (mx < w) {
move(mx+1, my, w, h); //Right
}
if (my < h) {
move(mx, my+1, w, h); // Up
}
if (mx > 0) {
move(mx-1, my, w, h); //Left
}
if (my > 0) {
move(mx, my-1, w, h); // Down
}
return ;
}
int main(int argc, char **argv) {
int w, h;
scanf("%d %d", &w, &h);
int px, py;
// Populate map
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
scanf(" %c", &map[i][j]);
// Set player coordinates
if (map[i][j] == 'P') {
py = i;
px = j;
}
}
}
for (int i=0; i < 100; i++) {
for(int j=0; j < 100; j++) {
visited[i][j] = false;
}
}
// Initiate traversal
move(px, py, w, h);
// Print result
printf("%d\n", counter);
return 0;
}

View File

@ -0,0 +1,87 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
char map[100][100];
int visited[100][100];
int counter = 0;
bool isDrafty(int x, int y) {
// Determines whether there's a trap in the immediate vicinity of the square we're standing on
return (map[y][x] == '.' && (map[y+1][x] == 'T' || map[y-1][x] == 'T' || map[y][x+1] == 'T' || map[y][x-1] == 'T'));
}
void move(int mx, int my, int w, int h) {
// Moves our x, y by 1 until a wall is found or becomes drafty
char c = map[my][mx];
// Avoid visiting visited nodes(endless loop occurs)
if (visited[my][mx]) {
return ;
}
visited[my][mx] = true;
// Stop if drafty or wall. Increment counter if gold is found.
if (c == '#') {
return ;
}
// printf("x: %d, y: %d, c: %c\n", mx, my, c);
if (c == 'G') {
counter++;
}
if(c == 'T' || isDrafty(mx, my)){
return ;
}
// Move (as long as we're not stepping out of bounds)
if (mx < w) {
move(mx+1, my, w, h); //Right
}
if (my < h) {
move(mx, my+1, w, h); // Up
}
if (mx > 0) {
move(mx-1, my, w, h); //Left
}
if (my > 0) {
move(mx, my-1, w, h); // Down
}
return ;
}
int main(int argc, char **argv) {
int w, h;
scanf("%d %d", &w, &h);
int px, py;
// Populate map
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
scanf(" %c", &map[i][j]);
// Set player coordinates
if (map[i][j] == 'P') {
py = i;
px = j;
}
}
}
for (int i=0; i < 100; i++) {
for(int j=0; j < 100; j++) {
visited[i][j] = false;
}
}
// Initiate traversal
move(px, py, w, h);
// Print result
printf("%d\n", counter);
return 0;
}

View File

@ -0,0 +1 @@
1-3;5;7;10-13

View File

@ -0,0 +1 @@
1;3;5;8;13

View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int problems = 0;
while (1) {
int start;
scanf("%d", &start);
char c;
scanf("%c", &c);
if (c == '-') {
int end;
scanf("%d", &end);
problems += end - start + 1;
char x = getchar();
if (x == ';') continue;
else break;
} else if (c == ';') {
problems += 1;
continue;
} else {
problems += 1;
break;
}
}
printf("%d\n", problems);
}

View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char c;
int idx = -1;
int counter = 0;
int nose = -1;
while ((c = getchar()) != '\n') {
// Eyes
if (c == ':' || c == ';') {
idx = counter;
} else if (c == '-' && (idx != -1)) {
nose = 1;
} else if ((c == ')' && (idx != -1)) ||(c == ')' && nose && (idx != -1)) ) {
printf("%d\n", idx);
idx = -1;
nose = 0;
} else {
idx = -1;
nose = 0;
}
counter++;
}
return 0;
}

View File

@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool sumEquals(int x, int y) {
int sum = 0;
while (x != 0) {
sum += x % 10;
x /= 10;
}
return sum == y;
}
int main(int argc, char **argv) {
int l, d, x;
scanf("%d", &l);
scanf("%d", &d);
scanf("%d", &x);
int n = 0;
for (int i=l; i<=d; i++) {
if (sumEquals(i, x)) {
n = i;
break;
}
}
int m = 0;
for (int i=d; i>=l; i--) {
if (sumEquals(i, x)) {
m = i;
break;
}
}
printf("%d\n%d\n", n,m);
return 0;
}