Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- char colToLetter(int col) {
- if(col == 0) return 'A';
- if(col == 1) return 'B';
- if(col == 2) return 'C';
- if(col == 4) return 'D';
- if(col == 5) return 'E';
- if(col == 6) return 'F';
- return '?';
- }
- class AirplaneSeating {
- public:
- AirplaneSeating(int n, const vector<string> &rows)
- : n(n), configuration(rows) { }
- void processGroup(int groupSize, const string &side, const string &position) {
- vector<int> sideIndices;
- if(side == "left")
- sideIndices = {0, 1, 2};
- else // "right"
- sideIndices = {4, 5, 6};
- int demandedIndex = -1;
- if(side == "left"){
- if(position == "window")
- demandedIndex = 0; // A
- else if(position == "aisle")
- demandedIndex = 2; // C
- } else {
- if(position == "aisle")
- demandedIndex = 4; // D
- else if(position == "window")
- demandedIndex = 6; // F
- }
- bool found = false;
- int foundRow = -1, foundStart = -1;
- for (int i = 0; i < n && !found; i++) {
- int possibleBlocks = 3 - groupSize + 1;
- for (int start = 0; start < possibleBlocks; start++) {
- bool blockFree = true;
- bool demandSatisfied = false;
- for (int j = 0; j < groupSize; j++) {
- int col = sideIndices[start + j];
- if (configuration[i][col] != '.'){
- blockFree = false;
- break;
- }
- if(col == demandedIndex)
- demandSatisfied = true;
- }
- if(blockFree && demandSatisfied) {
- found = true;
- foundRow = i;
- foundStart = start;
- break;
- }
- }
- }
- if (!found) {
- cout << "Cannot fulfill passengers requirements" << "\n";
- return;
- }
- vector<int> chosenCols;
- for (int j = 0; j < groupSize; j++){
- chosenCols.push_back(sideIndices[foundStart+j]);
- }
- vector<string> seatLabels;
- for(auto col : chosenCols){
- string lab = to_string(foundRow+1);
- lab.push_back(colToLetter(col));
- seatLabels.push_back(lab);
- }
- cout << "Passengers can take seats:";
- for(auto &lab : seatLabels){
- cout << " " << lab;
- }
- cout << "\n";
- for(auto col : chosenCols){
- configuration[foundRow][col] = '#';
- }
- for (int i = 0; i < n; i++) {
- string outLine;
- for (int j = 0; j < 7; j++) {
- if (i == foundRow) {
- bool isCurrent = false;
- for(auto col : chosenCols){
- if(j == col){
- isCurrent = true;
- break;
- }
- }
- if(isCurrent){
- outLine.push_back('X');
- continue;
- }
- }
- outLine.push_back(configuration[i][j]);
- }
- cout << outLine << "\n";
- }
- }
- private:
- int n;
- vector<string> configuration;
- };
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n;
- cin >> n;
- vector<string> rows(n);
- for (int i = 0; i < n; i++){
- cin >> rows[i];
- }
- AirplaneSeating airplane(n, rows);
- int m;
- cin >> m;
- for (int i = 0; i < m; i++){
- int groupSize;
- string side, position;
- cin >> groupSize >> side >> position;
- airplane.processGroup(groupSize, side, position);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement