B. Good String
https://codeforces.com/contest/1140/problem/B
해석이 너무 헷갈려서 여러 번 틀렸던 문제다..
>가 등장하면 오른쪽에 있는 string을 다 제거할 수 있고, <가 등장하면 왼쪽에 있는 string을 다 제거할 수 있다.
왼쪽부터 시작해 >가 처음 나오는 지점, 오른쪽부터 시작해 <가 처음 나오는 지점 중에 min값을 출력하면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <bits/stdc++.h> using namespace std; int t, n; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cin >> t; while (t--) { string s; cin >> n >> s; int left = 0, right = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '>') { break; } else left++; } for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == '<') { break; } else right++; } cout << min(left, right) << '\n'; } } | cs |
'Competition > codeforces' 카테고리의 다른 글
Codeforces Round #549 (Div. 2) A. The Doors (0) | 2019.04.01 |
---|---|
Educational Codeforces Round 62 (Rated for Div. 2) D. Minimum Triangulation (0) | 2019.04.01 |
Educational Codeforces Round 62 (Rated for Div. 2) A. Detective Book (0) | 2019.04.01 |
Codeforces Round #548 (Div. 2) A. Even Substrings (0) | 2019.03.30 |
Codeforces Round #527 (Div. 3) A. Uniform String (0) | 2019.03.30 |