Advertisement
Malinovsky239

Untitled

Nov 21st, 2011
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. #define N 10
  6.  
  7. using namespace std;
  8.  
  9. string move;
  10. char b[N][N];
  11.  
  12. void init() {
  13.     for (int i = 1; i < 9; i++)
  14.         for (int j = 1; j < 9; j++)
  15.             b[i][j] = '.';
  16.  
  17.     for (int i = 1; i < 9; i++)
  18.         b[i][2] = 'P', b[i][7] = 'p';  
  19.  
  20.     b[1][1] = b[8][1] = 'R';
  21.     b[2][1] = b[7][1] = 'N';
  22.     b[3][1] = b[6][1] = 'B';
  23.     b[4][1] = 'Q';
  24.     b[5][1] = 'K';
  25.  
  26.     for (int i = 1; i < 9; i++)
  27.         b[i][8] = b[i][1] - 'A' + 'a';
  28. }
  29.  
  30. int main() {
  31.     freopen("chess.in", "r", stdin);
  32.     freopen("chess.out", "w", stdout);
  33.  
  34.     int n;
  35.     cin >> n;
  36.    
  37.     init();
  38.    
  39.     for (int i = 0; i < n; i++) {
  40.         cin >> move;
  41.         int l = move.size();
  42.  
  43.         if (l == 3) {
  44.             if (i % 2) {
  45.                 b[7][8] = 'k';
  46.                 b[6][8] = 'r';
  47.                 b[5][8] = b[8][8] = '.';
  48.             }
  49.             else {
  50.                 b[7][1] = 'K';
  51.                 b[6][1] = 'R';
  52.                 b[5][1] = b[8][1] = '.';
  53.             }
  54.             continue;
  55.         }
  56.  
  57.         if (l == 5) {
  58.             if (i % 2) {
  59.                 b[3][8] = 'k';
  60.                 b[4][8] = 'r';
  61.                 b[1][8] = b[5][8] = '.';
  62.             }
  63.             else {
  64.                 b[3][1] = 'K';
  65.                 b[4][1] = 'R';
  66.                 b[1][1] = b[5][1] = '.';
  67.             }
  68.             continue;
  69.         }
  70.  
  71.         char turn = 0, piece;
  72.         if (l == 7)
  73.             turn = move[6];                
  74.  
  75.         int x = move[1] - 'a' + 1, y = move[2] - '0';
  76.         piece = b[x][y];
  77.         b[x][y] = '.';
  78.  
  79.         x = move[4] - 'a' + 1, y = move[5] - '0';
  80.         b[x][y] = piece;
  81.  
  82.         if (turn) b[x][y] = turn;                  
  83.     }
  84.  
  85.     for (int i = 8; i > 0; i--, cout << endl)
  86.         for (int j = 1; j < 9; j++)
  87.             cout << b[j][i];
  88.  
  89.     return 0;
  90. }
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement