#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char nome[ 51 ] ;
char cor[ 16 ] ;
char tam;
} camisa;
void shellsort( camisa * v, int n) {
int i, j, h;
camisa aux;
for ( h = 1 ; h < n; h = 3 * h + 1 ) ; // Calcula o h inicial.
while ( h > 0 ) {
h = ( h - 1 ) / 3 ; // Atualiza o valor de h.
for ( i = h; i < n; i++ ) {
aux = v[ i] ;
j = i;
// Comparação com base nas regras de ordenação.
while ( j >= h &&
( strcmp ( v
[ j
- h
] .
cor , aux.
cor ) > 0 || ( strcmp ( v
[ j
- h
] .
cor , aux.
cor ) == 0 && v
[ j
- h
] .
tam < aux.
tam ) || ( strcmp ( v
[ j
- h
] .
cor , aux.
cor ) == 0 && v
[ j
- h
] .
tam == aux.
tam && strcmp ( v
[ j
- h
] .
nome , aux.
nome ) > 0 ) ) ) { v[ j] = v[ j - h] ;
j -= h;
}
v[ j] = aux;
}
}
}
int main( ) {
int n, i, c = 0 ;
while ( 1 ) {
if ( n == 0 ) break ;
camisa cam[ n] ;
for ( i = 0 ; i < n; i++ ) {
scanf ( "%[^\n ]" , cam
[ i
] .
nome ) ; scanf ( "%s %c" , cam
[ i
] .
cor , & cam
[ i
] .
tam ) ; }
shellsort( cam, n) ;
for ( i = 0 ; i < n; i++ ) {
printf ( "%s %c %s\n " , cam
[ i
] .
cor , cam
[ i
] .
tam , cam
[ i
] .
nome ) ; }
c++;
}
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKdHlwZWRlZiBzdHJ1Y3QgewogICAgY2hhciBub21lWzUxXTsKICAgIGNoYXIgY29yWzE2XTsKICAgIGNoYXIgdGFtOwp9IGNhbWlzYTsKCnZvaWQgc2hlbGxzb3J0KGNhbWlzYSAqdiwgaW50IG4pIHsKICAgIGludCBpLCBqLCBoOwogICAgY2FtaXNhIGF1eDsKICAgIGZvciAoaCA9IDE7IGggPCBuOyBoID0gMyAqIGggKyAxKTsgLy8gQ2FsY3VsYSBvIGggaW5pY2lhbC4KICAgIHdoaWxlIChoID4gMCkgewogICAgICAgIGggPSAoaCAtIDEpIC8gMzsgLy8gQXR1YWxpemEgbyB2YWxvciBkZSBoLgogICAgICAgIGZvciAoaSA9IGg7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgYXV4ID0gdltpXTsKICAgICAgICAgICAgaiA9IGk7CiAgICAgICAgICAgIC8vIENvbXBhcmHDp8OjbyBjb20gYmFzZSBuYXMgcmVncmFzIGRlIG9yZGVuYcOnw6NvLgogICAgICAgICAgICB3aGlsZSAoaiA+PSBoICYmIAogICAgICAgICAgICAgICAgICAgKHN0cmNtcCh2W2ogLSBoXS5jb3IsIGF1eC5jb3IpID4gMCB8fCAKICAgICAgICAgICAgICAgICAgIChzdHJjbXAodltqIC0gaF0uY29yLCBhdXguY29yKSA9PSAwICYmIHZbaiAtIGhdLnRhbSA8IGF1eC50YW0pIHx8IAogICAgICAgICAgICAgICAgICAgKHN0cmNtcCh2W2ogLSBoXS5jb3IsIGF1eC5jb3IpID09IDAgJiYgdltqIC0gaF0udGFtID09IGF1eC50YW0gJiYgc3RyY21wKHZbaiAtIGhdLm5vbWUsIGF1eC5ub21lKSA+IDApKSkgewogICAgICAgICAgICAgICAgdltqXSA9IHZbaiAtIGhdOwogICAgICAgICAgICAgICAgaiAtPSBoOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZbal0gPSBhdXg7CiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIGludCBuLCBpLCBjID0gMDsKICAgIHdoaWxlICgxKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJm4pOwogICAgICAgIGlmIChuID09IDApIGJyZWFrOwogICAgICAgIGlmIChjICE9IDApIHByaW50ZigiXG4iKTsKCiAgICAgICAgY2FtaXNhIGNhbVtuXTsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIHdoaWxlIChnZXRjaGFyKCkgIT0gJ1xuJyk7CiAgICAgICAgICAgIHNjYW5mKCIlW15cbl0iLCBjYW1baV0ubm9tZSk7CiAgICAgICAgICAgIHNjYW5mKCIlcyAlYyIsIGNhbVtpXS5jb3IsICZjYW1baV0udGFtKTsKICAgICAgICB9CgogICAgICAgIHNoZWxsc29ydChjYW0sIG4pOwoKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIHByaW50ZigiJXMgJWMgJXNcbiIsIGNhbVtpXS5jb3IsIGNhbVtpXS50YW0sIGNhbVtpXS5ub21lKTsKICAgICAgICB9CgogICAgICAgIGMrKzsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==
stdin
OQpNYXJpYSBKb3NlCmJyYW5jbyBQCk1hbmdvamF0YSBNYW5jdWRhCnZlcm1lbGhvIFAKQ2V6YXIgVG9ycmVzIE1vCmJyYW5jbyBQCkJha2EgTGhhdQp2ZXJtZWxobyBQCkp1SnUgTWVudGluYQpicmFuY28gTQpBbWFybyBEaW5oYQp2ZXJtZWxobyBQCkFkYWJpIEZpbmhvCmJyYW5jbyBHClNldmVyaW5hIFJpZ3VkaW5oYQpicmFuY28gRwpDYXJsb3MgQ2hhZGUgTG9zbmEKdmVybWVsaG8gUAozCk1hcmlhIEpvYW8KYnJhbmNvIFAKTWFyY2lvIEd1ZXNzCnZlcm1lbGhvIFAKTWFyaWEgSm9zZQpicmFuY28gUAow
9
Maria Jose
branco P
Mangojata Mancuda
vermelho P
Cezar Torres Mo
branco P
Baka Lhau
vermelho P
JuJu Mentina
branco M
Amaro Dinha
vermelho P
Adabi Finho
branco G
Severina Rigudinha
branco G
Carlos Chade Losna
vermelho P
3
Maria Joao
branco P
Marcio Guess
vermelho P
Maria Jose
branco P
0