http://blog.csdn.net/AXuan_K/article/details/37922039
Test instructions: Given a chessboard, the position of each piece is output. The row numbers indicate the column letters.
Note: 1. Uppercase letters indicate white, lowercase letters are black, and punctuation in the table is not used.
2, the checkerboard of the order and the matrix of the row opposite, that is, the matrix last behavior of the first line of the board.
3. White is arranged in ascending order of rows and columns.
4. Black chess lines are sorted in descending order of rows and ascending by column.
5, the final output without punctuation, the column letter is uppercase.
Idea: Arrays store the type of pawn, and white moves from the last line to the first line, and black moves from the first line to the last line. If there is a pawn, output its position.
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Chara[6]={'K','Q','R','B','N','P'};7 Charb[6]={'k','Q','R','b','N','P'};8 Charmap[ +][ +];9 Main ()Ten { One inti,j,s1=0, s2=0, K; A for(i=1; i<= -; i++) - { - for(j=1; j<= -; j + +) the { -Cin>>Map[i][j]; - if(map[i][j]=='P') -s1++; + if(map[i][j]=='P') -s2++; + } A } atprintf"White :"); - for(k=0;k<6; k++) - { - for(i= -; i>=1; i--) - { - for(j=1; j<= -; j + +) in { - if(k<=4&&i%2==0&&j%4==3) to { + if(map[i][j]==A[k]) - { theprintf"%c%c%d,", A[k],'a'+ (j+1)/4-1,9-i/2); * } $ }Panax Notoginseng if(k==5&&i%2==0&&j%4==3) - { the if(map[i][j]==A[k]) + { As1--; the if(s1==0) +printf"%c%d\n",'a'+ (j+1)/4-1,9-i/2); - Else $printf"%c%d,",'a'+ (j+1)/4-1,9-i/2); $ } - } - } the } - }Wuyiprintf"Black:"); the for(k=0;k<6; k++) - { Wu for(i=1; i<= -; i++) - { About for(j=1; j<= -; j + +) $ { - if(k<=4&&i%2==0&&j%4==3) - { - if(map[i][j]==B[k]) A { +printf"%c%c%d,", A[k],'a'+ (j+1)/4-1,9-i/2); the } - } $ if(k==5&&i%2==0&&j%4==3) the { the if(map[i][j]==B[k]) the { thes2--; - if(s2==0) inprintf"%c%d\n",'a'+ (j+1)/4-1,9-i/2); the Else theprintf"%c%d,",'a'+ (j+1)/4-1,9-i/2); About } the } the } the } + } -}
View Code
POJ2996 help Me with the Game big simulation