Added solutions for phase 2

This commit is contained in:
Abreu 2021-10-21 21:53:16 -03:00
parent 6a04e7a8fa
commit bfeea1f1ef
No known key found for this signature in database
GPG Key ID: 64835466FF55F7E1
3 changed files with 98 additions and 3 deletions

View File

@ -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(" ");

55
2021/2/olhos.c Normal file
View File

@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#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;
}

40
2021/2/operador.c Normal file
View File

@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
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;
}