133 lines
3.0 KiB
C
Raw Normal View History

2023-12-01 13:35:13 +01:00
#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;
}