-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringmaior.c
38 lines (30 loc) · 1.2 KB
/
stringmaior.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <string.h>
#define MAX_STR_LENGTH 100
int main() {
char strings[100][MAX_STR_LENGTH]; // matriz para armazenar as strings
char longest_length[MAX_STR_LENGTH] = ""; // para armazenar a maior string em comprimento
char longest_lexico[MAX_STR_LENGTH] = ""; // para armazenar a maior string lexicograficamente
int N;
// Ler o número de strings
scanf("%d", &N);
getchar(); // Consumir o caractere de nova linha após o número inteiro
// Ler as N strings
for (int i = 0; i < N; i++) {
fgets(strings[i], MAX_STR_LENGTH, stdin);
strings[i][strcspn(strings[i], "\n")] = '\0'; // Remover o caractere de nova linha
// Verificar maior string em termos de comprimento
if (strlen(strings[i]) > strlen(longest_length)) {
strcpy(longest_length, strings[i]);
}
// Verificar maior string lexicograficamente
if (strcmp(strings[i], longest_lexico) > 0) {
strcpy(longest_lexico, strings[i]);
}
}
// Imprimir a maior string em termos de comprimento
printf("%s\n", longest_length);
// Imprimir a maior string lexicograficamente
printf("%s\n", longest_lexico);
return 0;
}