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,27 @@
26
clank
bong
click
tap
poing
clonk
clack
ping
tip
cloing
tic
cling
bing
pong
clang
pang
clong
tac
boing
boink
cloink
rattle
clock
toc
clink
tuc

View File

@ -0,0 +1,15 @@
14
bump
tip
whack
bump
clock
clank
pong
boink
whack
pang
tip
tuc
tuc
clank

View File

@ -0,0 +1,11 @@
10
dink
pong
clang
whack
bump
click
thumb
clank
pang
boing

View File

@ -0,0 +1,133 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define MAX 100001
// FIXME: Not passing all test cases
bool caps = false;
bool shift = false;
void toggleCaps() {
caps = !caps;
}
char strokeToKey(char stroke[30]) {
char key = '-';
if (strcmp(stroke, "clank") == 0) {
key = 'a';
} else if (strcmp(stroke, "bong") == 0) {
key = 'b';
} else if (strcmp(stroke, "click") == 0) {
key = 'c';
} else if (strcmp(stroke, "tap") == 0) {
key = 'd';
} else if (strcmp(stroke, "poing") == 0) {
key = 'e';
} else if (strcmp(stroke, "clonk") == 0) {
key = 'f';
} else if (strcmp(stroke, "clack") == 0) {
key = 'g';
} else if (strcmp(stroke, "ping") == 0) {
key = 'h';
} else if (strcmp(stroke, "tip") == 0) {
key = 'i';
} else if (strcmp(stroke, "cloing") == 0) {
key = 'j';
} else if (strcmp(stroke, "tic") == 0) {
key = 'k';
} else if (strcmp(stroke, "cling") == 0) {
key = 'l';
} else if (strcmp(stroke, "bing") == 0) {
key = 'm';
} else if (strcmp(stroke, "pong") == 0) {
key = 'n';
} else if (strcmp(stroke, "clang") == 0) {
key = 'o';
} else if (strcmp(stroke, "pang") == 0) {
key = 'p';
} else if (strcmp(stroke, "clong") == 0) {
key = 'q';
} else if (strcmp(stroke, "tac") == 0) {
key = 'r';
} else if (strcmp(stroke, "boing") == 0) {
key = 's';
} else if (strcmp(stroke, "boink") == 0) {
key = 't';
} else if (strcmp(stroke, "cloink") == 0) {
key = 'u';
} else if (strcmp(stroke, "rattle") == 0) {
key = 'v';
} else if (strcmp(stroke, "clock") == 0) {
key = 'w';
} else if (strcmp(stroke, "toc") == 0) {
key = 'x';
} else if (strcmp(stroke, "clink") == 0) {
key = 'y';
} else if (strcmp(stroke, "tuc") == 0) {
key = 'z';
} else if (strcmp(stroke, "whack") == 0) {
key = ' ';
} else if (strcmp(stroke, "pop") == 0) {
key = '%';
}
else if (strcmp(stroke, "bump") == 0) {
toggleCaps();
key = '$';
} else if (strcmp(stroke, "dink") == 0) {
shift = true;
key = '>';
} else if (strcmp(stroke, "dink") == 0) {
shift = false;
key = '<';
}
// printf("%s : %c\n", stroke, key);
return key;
}
char upOrDown(char c) {
if ((!shift && caps) || (shift && !caps)) {
return toupper(c);
}
caps = false;
return c;
}
void writeToArr(char sentence[MAX], char stroke[30], int *idx) {
char key = strokeToKey(stroke);
if ((key <= 'z' && key >= 'a') || key == ' ') {
sentence[*idx] = upOrDown(key);
*idx += 1;
} else if (key == '%') {
sentence[*idx] = '-';
*idx -= 1;
} else {
return;
}
}
void printArr(char sentence[MAX], int length) {
for (int i=0; i<length; i++) {
printf("%c", sentence[i]);
}
printf("\n");
}
int main(int argc, char **argv) {
int lines;
scanf("%d", &lines);
char sentence[MAX];
int idx = 0;
for (int i=0; i<lines; i++) {
char stroke[30];
scanf("%s", stroke);
writeToArr(sentence, stroke, &idx);
}
printArr(sentence, idx);
return 0;
}

View File

@ -0,0 +1,97 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define MAX 100001
caps = false;
shift = false;
void toggleCaps() {
caps = !caps;
}
char strokeToKey(char stroke[30]) {
char key = '-';
if (strcmp(stroke, "clank") == 0) key = 'a';
else if (strcmp(stroke, "bong") == 0) key = 'b';
else if (strcmp(stroke, "click") == 0) key = 'c';
else if (strcmp(stroke, "clack") == 0) key = 'd';
else if (strcmp(stroke, "tap") == 0) key = 'e';
else if (strcmp(stroke, "poing") == 0) key = 'f';
else if (strcmp(stroke, "clonk") == 0) key = 'g';
else if (strcmp(stroke, "clack") == 0) key = 'h';
else if (strcmp(stroke, "ping") == 0) key = 'i';
else if (strcmp(stroke, "tip") == 0) key = 'j';
else if (strcmp(stroke, "cloing") == 0) key = 'k';
else if (strcmp(stroke, "tic") == 0) key = 'l';
else if (strcmp(stroke, "cling") == 0) key = 'm';
else if (strcmp(stroke, "bing") == 0) key = 'n';
else if (strcmp(stroke, "pong") == 0) key = 'o';
else if (strcmp(stroke, "clang") == 0) key = 'p';
else if (strcmp(stroke, "tac") == 0) key = 'q';
else if (strcmp(stroke, "boing") == 0) key = 'r';
else if (strcmp(stroke, "boink") == 0) key = 's';
else if (strcmp(stroke, "cloinc") == 0) key = 't';
else if (strcmp(stroke, "rattle") == 0) key = 'u';
else if (strcmp(stroke, "squeal") == 0) key = 'v';
else if (strcmp(stroke, "clock") == 0) key = 'w';
else if (strcmp(stroke, "toc") == 0) key = 'x';
else if (strcmp(stroke, "clink") == 0) key = 'y';
else if (strcmp(stroke, "tuc") == 0) key = 'z';
else if (strcmp(stroke, "whack") == 0) key = ' ';
else if (strcmp(stroke, "pop") == 0) key = '%';
else if (strcmp(stroke, "bump") == 0) {
toggleCaps();
key = '$';
}
else if (strcmp(stroke, "dink") == 0) {
shift = true;
key = '>';
}
else if (strcmp(stroke, "dink") == 0) {
shift = false;
key = '<';
}
}
char upOrDown(char c) {
if (shift || caps) return toupper(c);
return c;
}
void writeToArr(char sentence[MAX], char stroke[30], int *idx) {
char key = strokeToKey(stroke);
if ((key <= 'z' && key >= 'a') || key == ' ') {
sentence[*idx] = upOrDown(key);
*idx++;
} else if (key == '%') {
sentence[*idx] = '-';
*idx--;
}
}
void printArr(char sentence[MAX], int length) {
for (int i=0; i<length; i++) {
printf("%c", sentence[i]);
}
printf("\n");
}
int main(int argc, char **argv) {
int lines;
scanf("%d", &lines);
char sentence[MAX];
int idx = 0;
for (int i=0; i<lines; i++) {
char stroke[30];
scanf("%s", stroke);
writeToArr(sentence, stroke, &idx);
}
printArr(sentence, idx);
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,2 @@
1
7

View File

@ -0,0 +1,2 @@
2
2 12

View File

@ -0,0 +1,2 @@
11
2 3 4 5 6 7 8 9 10 11 12

View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX 12
int rollProbability(int number) {
int sum = 0;
for (int i=1; i<=6; i++) {
for (int j=1; j<=6; j++) {
if (i+j == number) {
sum++;
}
}
}
return sum;
}
int main(int argc, char **argv) {
int hotels;
int distances[MAX];
scanf("%d", &hotels);
float sum = 1/6;
for (int i=0; i<hotels; i++) {
scanf("%d", &distances[i]);
}
for (int i=0; i<hotels; i++) {
sum += rollProbability(distances[i]) / 36.0;
}
printf("%f\n", sum);
return 0;
}

View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX 12
int main(int argc, char **argv) {
int hotels;
int distances[MAX];
scanf("%d", &hotels);
float sum = 0;
for (int i=0; i<hotels; i++) {
scanf("%d", &distances[i]);
}
for (int i=0; i<hotels; i++) {
sum += distances[i]/6.0;
}
printf("%f\n", sum);
return 0;
}

Binary file not shown.

View File

View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX 100001
int main(int argc, char **argv) {
int n;
scanf("%d", &n);
int locations[MAX] = {0};
for (int i = 1; i <= n; ++i) {
scanf("%d", &locations[i]);
}
int temp = 0;
for (int i = 1; i <= n; ++i) {
if (locations[i] == i) {
continue;
}
temp = locations[i];
locations[i] = locations[temp];
locations[temp] = temp;
}
return 0;
}

View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX 100001
int main(int argc, char **argv) {
int n;
scanf("%d", &n);
int locations[MAX] = {0};
for (int i = 0; i < n; ++i) {
scanf("%d", &locations[i]);
}
for (int i = 0; i < n; ++i) {
printf("%d ", locations[i]);
}
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000
int main(int argc, char **argv) {
int max;
int lines;
scanf("%d %d", &max, &lines);
for (int i=0; i<lines; i++) {
char name[MAX];
int speed;
scanf("%s %d", name, &speed);
if (speed >= max) {
printf("%s opin", name);
} else {
printf("%s lokud", name);
}
printf("\n");
}
}

Binary file not shown.