fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Codeforces Round 1018-A (Div. 1 + Div. 2) (C++) Wonderful Sticks
최초 업로드: 2025-04-19 17:37:59
최근 수정 시간: 2025-08-30 14:08:23
게시자: rlatjwls3333
카테고리: Codeforces
조회수: 19
# A. Wonderful Sticks [문제 링크](https://codeforces.com/contest/2096/problem/A) ## Problem Statement You are the proud owner of $n$ sticks. Each stick has an integer length from $1$ to $n$. The lengths of the sticks are **distinct**. You want to arrange the sticks in a row. There is a string $s$ of length $n-1$ that describes the requirements of the arrangement. Specifically, for each $i$ from $1$ to $n-1$: - If $s_i = \texttt{<}$, then the length of the stick at position $i+1$ must be **smaller** than all sticks before it; - If $s_i = \texttt{>}$, then the length of the stick at position $i+1$ must be **larger** than all sticks before it. Find any valid arrangement of sticks. We can show that an answer always exists. ## Input Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows. The first line of each test case contains a single integer $n$ ($2 \le n \le 100$) — the number of sticks. The second line of each test case contains a single string $s$ of length $n-1$ consisting of characters $\texttt{<}$ and $\texttt{>}$ — describing the requirements of the arrangement. ## Output For each test case, output $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$, the $a_i$ are distinct) — the lengths of the sticks in order. If there are multiple solutions, print any of them. ## 풀이 #### 뒤에서부터 순서대로 < 인 공간 매핑, 그 후 앞에서부터 나머지공간 매핑하면 된다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) { int n; string s; cin >> n >> s; vector<int> res(n); int cnt=1; for(int i=n-2;i>=0;i--) { if(s[i]=='<') res[i+1] = cnt++; } for(int i=0;i<n;i++) { if(res[i]==0) res[i] = cnt++; } for(int e:res) cout << e << ' '; cout << '\n'; } } ```