Official

A - Treasure Chest Editorial by en_translator


Find the positions of | and * in the string \(S\) and compare them to check if the conditions are satisfied.

The following are sample codes.

Sample code in C++

#include <iostream>
#include <string>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;

    int v_first = -1, s, v_second;
    for (int i = 0; i < N; ++i) {
        if (S[i] == '|') {
            if (v_first < 0)
                v_first = i;
            else
                v_second = i;
        }
        if (S[i] == '*')
            s = i;
    }

    if (v_first < s && s < v_second)
        cout << "in" << endl;
    else
        cout << "out" << endl;

    return 0;
}

Sample code in Python

N = int(input())
S = input()

v_first = S.index('|')
s = S.index('*')
v_second = S.rindex('|')

if v_first < s < v_second:
    print('in')
else:
    print('out')

posted:
last update: