Advertisement
Spocoman

02. Chess

Feb 10th, 2024
1,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     string line, white, black;
  9.  
  10.     vector<vector<char>> chessBoard = vector<vector<char>>(8, vector<char>(8, '.'));
  11.  
  12.     for (int r = 0; r < 8; r++) {
  13.         getline(cin, line);
  14.         for (int c = 0; c < 8; c++) {
  15.             if (line[c] != '.') {
  16.                 char chr = line[c];
  17.                 if (isupper(chr)) {
  18.                     white += chr;
  19.                 }
  20.                 else {
  21.                     black += chr;
  22.                 }
  23.                 chessBoard[r][c] = isupper(chr) ? tolower(chr) : toupper(chr);
  24.             }
  25.         }
  26.     }
  27.  
  28.     cout << (white.empty() ? "<no white figures>" : white) << endl;
  29.     cout << (black.empty() ? "<no black figures>" : black) << endl;
  30.  
  31.     for (int r = 0; r < 8; r++) {
  32.         for (int c = 0; c < 8; c++) {
  33.             cout << chessBoard[r][c];
  34.         }
  35.         cout << endl;
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement