Official

B - Train Reservation Editorial by en_translator Editorial for printing


For each train, check if seat \(X\) is vacant.

A seat letter \(X\) can be concisely converted to the corresponding index by subtracting the character code of A from that of \(X\).

Sample code (Python)

N, X = input().split()
N = int(N)
X = ord(X) - ord('A')
S = [input() for _ in range(N)]
ans = False
for s in S:
    ans |= s[X] == "o"
if ans:
    print("Yes")
else:
    print("No")

Sample code (C++)

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    char X;
    cin >> N >> X;
    vector<string> S(N);
    for (int i = 0; i < N; i++) cin >> S[i];
    
    bool ans = false;
    for (int i = 0; i < N; i++) ans |= S[i][X - 'A'] == 'o';
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

posted:
last update: