#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
struct musica {
char nome[ 100 ] ;
char estilo[ 100 ] ;
int rank;
} ;
typedef struct musica Musica;
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
) ; }
Musica * temp;
for ( i= 0 ; i< 4 ; i++ ) {
for ( j= i+ 1 ; j< 4 ; j++ ) {
if ( a[ i] -> rank > a[ j] -> rank) {
temp = a[ i] ;
a[ i] = a[ j] ;
a[ j] = temp;
}
}
}
//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+CiNpbmNsdWRlIDxsb2NhbGUuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKc3RydWN0IG11c2ljYSB7CgljaGFyIG5vbWVbMTAwXTsKCWNoYXIgZXN0aWxvWzEwMF07CglpbnQgcmFuazsKfTsKCnR5cGVkZWYgc3RydWN0IG11c2ljYSBNdXNpY2E7CgppbnQgbWFpbiAodm9pZCkgewoJaW50IGksajsKCU11c2ljYSAqYVs4XTsKCglzZXRsb2NhbGUoTENfQUxMLCAiUG9ydHVndWVzZSIpOwoKCWZvciAoaT0wOyBpPDQ7IGkrKykgewogICAgICAgIGFbaV0gPSBtYWxsb2Moc2l6ZW9mKE11c2ljYSkpOwoJCXByaW50ZiAoIk5vbWUgZGEgbcO6c2ljYTogIik7CgkJZ2V0cyAoYVtpXS0+bm9tZSk7CgoJCXByaW50Zi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