Moved kattis from Uni repo
This commit is contained in:
27
kattis/problems/27_10_23/keylogger/1.in
Normal file
27
kattis/problems/27_10_23/keylogger/1.in
Normal 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
|
15
kattis/problems/27_10_23/keylogger/2.in
Normal file
15
kattis/problems/27_10_23/keylogger/2.in
Normal file
@ -0,0 +1,15 @@
|
||||
14
|
||||
bump
|
||||
tip
|
||||
whack
|
||||
bump
|
||||
clock
|
||||
clank
|
||||
pong
|
||||
boink
|
||||
whack
|
||||
pang
|
||||
tip
|
||||
tuc
|
||||
tuc
|
||||
clank
|
11
kattis/problems/27_10_23/keylogger/3.in
Normal file
11
kattis/problems/27_10_23/keylogger/3.in
Normal file
@ -0,0 +1,11 @@
|
||||
10
|
||||
dink
|
||||
pong
|
||||
clang
|
||||
whack
|
||||
bump
|
||||
click
|
||||
thumb
|
||||
clank
|
||||
pang
|
||||
boing
|
133
kattis/problems/27_10_23/keylogger/main.c
Normal file
133
kattis/problems/27_10_23/keylogger/main.c
Normal 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;
|
||||
}
|
97
kattis/problems/27_10_23/keylogger/main.c.orig
Normal file
97
kattis/problems/27_10_23/keylogger/main.c.orig
Normal 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;
|
||||
}
|
BIN
kattis/problems/27_10_23/keylogger/program
Executable file
BIN
kattis/problems/27_10_23/keylogger/program
Executable file
Binary file not shown.
Reference in New Issue
Block a user