#include #include #include #define M 16 struct figurka { char type; char row; char col; }; int wh; struct figurka white[16]; int whiteend=0; int blackend=0; struct figurka black[16]; int convert(char c){ switch(c){ case 'K': return 1; case 'Q': return 2; case 'R': return 3; case 'B': return 4; case 'N': return 5; case 'P': return 6; } return 7; } int compare(const void* a, const void *b){ struct figurka *f,*s; f = (struct figurka*)a; s = (struct figurka*)b; /* printf("%d>%d\n",f->type, s->type);*/ if(f->type < s->type) return -1; if(f->type > s->type) return 1; if( ((f->row < s->row) && wh) || ((f->row > s->row) && !wh)) return -1; if( ((f->row > s->row) && wh) || ((f->row < s->row) && !wh)) return 1; if( f->col < s->col) return -1; if( f->col > s->col) return 1; return 0; /* podle typu, podle row(podle barvy), podle col */ } void nacti() { char buffer[35]; char i,j; for(i='8';i>'0';i--) { gets(buffer); gets(buffer); for(j='a';j<='h';j++){ if(islower(buffer[(j-'a')*4+2])) { black[blackend].type=convert(toupper(buffer[(j-'a')*4+2])); black[blackend].row=i; black[blackend].col=j; blackend++; } if(isupper(buffer[(j-'a')*4+2])) { white[whiteend].type=convert(toupper(buffer[(j-'a')*4+2])); white[whiteend].row=i; white[whiteend].col=j; whiteend++; } } } } void init(){ int i; for(i=0; i<16; i++){ white[i].type = 8; black[i].type = 8; } } void vypis(struct figurka* f){ static char table[] = " KQRBNP"; int i; for(i=0; i<16; i++){ if(i>0) printf(","); if(f[i].type > 7) break; if(f[i].type == 6) ; else printf("%c",table[f[i].type]); printf("%c%c",f[i].col,f[i].row); } puts(""); } int main(void) { int i; init(); nacti(); /* for(i=0;i<16;i++){ printf("%d %c %c\n", white[i].type, white[i].col, white[i].row); } puts(""); for(i=0;i<16;i++){ printf("%d %c %c\n", black[i].type, black[i].row, black[i].col); } */ wh=1; qsort(white,16,sizeof(struct figurka),compare); printf("White: "); vypis(white); wh=0; qsort(black,16,sizeof(struct figurka),compare); printf("Black: "); vypis(black); return 0; }