#include <stdio.h>
#include <string.h>
int main() {
int x;
scanf("%d", &x);
int p[x], troca=0;
char n[x][20], aux[20];
for(int i=0; i<x; i++){
scanf("%s", n[i]);
scanf("%d", &p[i]);
}
for(int i=0; i<x-1; i++){
for(int j=0; j<x-i-1; j++){
if(strcmp(n[j], n[j+1])>0){
//troca Nomes.
strcpy(aux, n[j]);
strcpy(n[j], n[j+1]);
strcpy(n[j+1], aux);
// Troca a pontuação junto com os nomes
troca=p[j];
p[j]=p[j+1];
p[j+1]=troca;
}
}
}
for(int i=0; i<x-1; i++){
for(int j=0; j<x-i-1; j++){
if(p[j]<p[j+1]){
//troca pontuação
troca=p[j];
p[j]=p[j+1];
p[j+1]=troca;
//troca nomes juntos com a pontuação.
strcpy(aux, n[j]);
strcpy(n[j], n[j+1]);
strcpy(n[j+1], aux);
}
}
}
for(int i=0; i<x; i++){
printf("%s\n", n[i]);
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: