어흥
[CodeForces] Kuroni and Simple Strings (C++) 본문
728x90
반응형
문제 링크: https://codeforces.com/contest/1305/problem/B
1. 주의할점
- 첫번째 output의 답으로는 0혹은 1밖에 나오지 않는다
2. 구현
- Stack을 이용 or DoublePointer 이용
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
string str;
cin >> str;
vector<int> v;
int l = 0, r = str.size() - 1;
while (l < r) {
while (1) {
if (str[l] == '(') break;
else l++;
}
while (1) {
if (str[r] == ')') break;
else r--;
}
if (l >= r) break;
v.push_back(l + 1);
v.push_back(r + 1);
l++; r--;
}
sort(v.begin(), v.end());
if (v.empty()) cout << 0;
else {
cout << 1 << '\n';
cout << v.size() << '\n';
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
}
return 0;
}
728x90
반응형
'알고리즘 > 코드포스' 카테고리의 다른 글
[CodeForces] Even Subset Sum Problem (C++) (0) | 2020.03.08 |
---|---|
[CodeForces] Assigning to Classes (C++) (0) | 2020.03.07 |
[CodeForces] Longest Palindrome (C++) (0) | 2020.03.07 |
[CodeForces] Kuroni and Impossible Calculation (C++) (0) | 2020.03.04 |
[CodeForces] Kuroni and the Gifts (C++) (0) | 2020.03.04 |
Comments