-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2479 - Ordenando a Lista de Crianças do Papai Noel.c
50 lines (43 loc) · 1.29 KB
/
2479 - Ordenando a Lista de Crianças do Papai Noel.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
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <string.h>
int main() {
int num, i, h, k; scanf("%d", &num);
char nomes[num][30];
char temp[30];
int comportaram = 0, nao_comportaram = 0;
// Leitura dos nomes (prefiro esse método que o fgets)
for (i = 0; i < num; i++) {
scanf(" %[^\n]", nomes[i]);
}
//Comparar caractere por caractere até achar a o maior e fazer o Bubble sort
for (h = 0; h < num; h++){
for (i = 1; i < num; i++) {
k = 2;
while (nomes[i-1][k] == nomes[i][k]){
k++;
}
if (nomes[i-1][k] > nomes[i][k]){
strcpy(temp, nomes[i-1]);
strcpy(nomes[i-1], nomes[i]);
strcpy(nomes[i], temp);
}
}
}
//Contagem de bonzinhos e mauzinhos
for (i = 0; i < num; i++) {
if (nomes[i][0] == '+'){
comportaram++;
}else{
nao_comportaram++;
}
}
//Imprime caractere por caractere, achei paia mas enfim :/
for (h = 0; h < num; h++){
for (i = 2; i < strlen(nomes[h]); i++) {
printf("%c", nomes[h][i]);
}
printf("\n");
}
printf("Se comportaram: %d | Nao se comportaram: %d\n", comportaram, nao_comportaram);
return 0;
}