Click
Here to go back to the homepage.
Emag Eht Htiw Em Pleh Solution:
#include <bits/stdc++.h>
using namespace std;
vector<string> stringSplit(const string s, char delimiter){
vector<string> tokens;
string token;
istringstream tokenStream(s);
while (getline(tokenStream, token, delimiter)){
tokens.push_back(token);
}
return tokens;
}
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
string boardSeparator = "+---+---+---+---+---+---+---+---+";
string board[8] = {"|:::|...|:::|...|:::|...|:::|...|",
"|...|:::|...|:::|...|:::|...|:::|",
"|:::|...|:::|...|:::|...|:::|...|",
"|...|:::|...|:::|...|:::|...|:::|",
"|:::|...|:::|...|:::|...|:::|...|",
"|...|:::|...|:::|...|:::|...|:::|",
"|:::|...|:::|...|:::|...|:::|...|",
"|...|:::|...|:::|...|:::|...|:::|"};
string line;
getline(cin, line);
vector<string> pieces = stringSplit(line.substr(7), ',');
for(string piece : pieces){
char id = piece.length() == 3? piece[0] : 'P';
int col = piece.length() == 3? piece[1] - 'a' : piece[0] - 'a';
board[piece[piece.length() - 1] - '1'][col * 4 + 2] = id;
}
getline(cin, line);
pieces = stringSplit(line.substr(7), ',');
for(string piece : pieces){
char id = piece.length() == 3? tolower(piece[0]) : 'p';
int col = piece.length() == 3? piece[1] - 'a' : piece[0] - 'a';
board[piece[piece.length() - 1] - '1'][col * 4 + 2] = id;
}
int i = 0;
cout << boardSeparator << endl;
for(int i = 7; i >= 0; i--){
cout << board[i] << endl << boardSeparator << endl;
}
return 0;
}