From bfeea1f1efb32e3dd09adfe492604638faeb757a Mon Sep 17 00:00:00 2001 From: Abreu Date: Thu, 21 Oct 2021 21:53:16 -0300 Subject: [PATCH] Added solutions for phase 2 --- 2021/1/X9.c | 6 +++--- 2021/2/olhos.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 2021/2/operador.c | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 2021/2/olhos.c create mode 100644 2021/2/operador.c diff --git a/2021/1/X9.c b/2021/1/X9.c index 3e42bc9..6ef9852 100644 --- a/2021/1/X9.c +++ b/2021/1/X9.c @@ -4,12 +4,12 @@ char *readKey () { int i, buffer = 76; /* Largura da maior palavra na lĂ­ngua portuguesa */ - char c, *input = malloc(buffer * sizeof(*input)); + char c, *input = malloc(buffer * sizeof(char)); for (i = 0; (c = getchar()) != EOF && isalnum(c); i++) { if (i == buffer - 1) { buffer += buffer; - input = realloc(input, buffer * sizeof(*input)); + input = realloc(input, buffer * sizeof(char)); } input[i] = c; } @@ -30,7 +30,7 @@ int main () { if (isalpha(c)) printf("%c", zion[c - 'a']); else - printf("%c", zion[26 + (c - '0')]); + printf("%c", zion['z' - 'a' + 1 + (c - '0')]); } printf("\n"); scanf(" "); diff --git a/2021/2/olhos.c b/2021/2/olhos.c new file mode 100644 index 0000000..170ff9f --- /dev/null +++ b/2021/2/olhos.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#define MAX 151 + +char ** readWords (int w) { + int i; + char **words = malloc(w * sizeof(char*)); + + for (i = 0; i < w; i++) { + words[i] = malloc(MAX * sizeof(char)); + scanf(" %s", words[i]); + } + return words; +} + +bool isRepeated (char **words, int i, int size) { + int j; + + if (strlen(words[i]) < 3 + || !strcmp(words[i], "uma") + || !strcmp(words[i], "com") + || !strcmp(words[i], "por") + || !strcmp(words[i], "que") + || !strcmp(words[i], "para")) + return false; + for (j = i + 1; j < size; j++) + if (!strcmp(words[i],words[j])) + return true; + return false; +} + +int countRepetitions (char **words, int size) { + int i, repetitions = 0; + + for (i = 0; i < size - 1; i++) { + if (isRepeated(words, i, size)) + repetitions++; + free(words[i]); + } + free(words); + return repetitions; +} + +int main () { + int size, n = 0; + + for (scanf(" %d", &n); n > 0; n--) { + scanf(" %d", &size); + printf("%d ocorrencia(s) de falha na matrix\n", + countRepetitions(readWords(size), size)); + } + return 0; +} diff --git a/2021/2/operador.c b/2021/2/operador.c new file mode 100644 index 0000000..426cdeb --- /dev/null +++ b/2021/2/operador.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +bool closestPhone(int *x, int *y) { + int phones, route_x, route_y; + double distance, closest; + + if (!scanf(" %d", &phones) || phones <= 0) + return false; + + scanf(" %d %d", x, y); + closest = sqrt(pow(abs(5 - *x),2) + pow(abs(5 - *y),2)); + + while (--phones > 0) { + scanf(" %d %d", &route_x, &route_y); + distance = sqrt(pow(abs(5 - route_x),2) + pow(abs(5 - route_y),2)); + if (distance > closest) + continue; + closest = distance; + *x = route_x; + *y = route_y; + } + return true; +} + +int main () { + int x, y, n = 0; + + for (scanf(" %d", &n); n > 0; n--) { + if (!closestPhone(&x, &y)) + printf("Ihh rapaiz, foi muito bom te conhecer, F proceis.\n"); + else if (x == y && y == 5) + printf("meu amigo olha o telefone ai do teu lado! Mas as coordenadas sao x = 5 e y = 5...\n"); + else + printf("AHAAA achei, corre malucoo as coordenadas sao x = %d, y = %d\n", x, y); + } + return 0; +}