#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
struct musica {
char nome[ 100 ] ;
char estilo[ 100 ] ;
int rank;
} ;
typedef struct musica Musica;
int compararMusicas( const void * musica1, const void * musica2) {
Musica* m1 = * ( ( Musica** ) musica1) ;
Musica* m2 = * ( ( Musica** ) musica2) ;
return m1-> rank- m2-> rank;
}
int main ( void ) {
int i, j;
Musica * a[ 8 ] ;
for ( i= 0 ; i< 4 ; i++ ) {
a
[ i
] = malloc ( sizeof ( Musica
) ) ;
printf ( "Ranking da música: " ) ; scanf ( "%d" ,& ( a
[ i
] -> rank
) ) ;
}
//RANKING DIGITADO DESORDENADO
for ( i= 0 ; i< 4 ; i++ ) {
printf ( "RANK %d\t %s\t %s\t \n " , a
[ i
] -> rank
, a
[ i
] -> nome
, a
[ i
] -> estilo
) ; }
qsort ( a
, 4 , sizeof ( Musica
* ) , compararMusicas
) ;
//RANKING ORDEM
for ( i= 0 ; i< 4 ; i++ ) {
printf ( "RANK %d\t %s\t %s\t \n " , a
[ i
] -> rank
, a
[ i
] -> nome
, a
[ i
] -> estilo
) ; }
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxsb2NhbGUuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKc3RydWN0IG11c2ljYSB7CgljaGFyIG5vbWVbMTAwXTsKCWNoYXIgZXN0aWxvWzEwMF07CglpbnQgcmFuazsKfTsKCnR5cGVkZWYgc3RydWN0IG11c2ljYSBNdXNpY2E7CgppbnQgY29tcGFyYXJNdXNpY2FzKGNvbnN0IHZvaWQqIG11c2ljYTEsIGNvbnN0IHZvaWQqIG11c2ljYTIpewogICAgTXVzaWNhKiBtMSA9ICooKE11c2ljYSoqKW11c2ljYTEpOwogICAgTXVzaWNhKiBtMiA9ICooKE11c2ljYSoqKW11c2ljYTIpOwoKICAgIHJldHVybiBtMS0+cmFuay1tMi0+cmFuazsKfQoKaW50IG1haW4gKHZvaWQpIHsKCWludCBpLGo7Cgl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