티스토리 뷰
https://www.acmicpc.net/problem/5430
5430번: AC
각 테스트 케이스에 대해서, 입력으로 주어진 정수 배열에 함수를 수행한 결과를 출력한다. 만약, 에러가 발생한 경우에는 error를 출력한다.
www.acmicpc.net
생각보다 쉽게 풀려서 다행인 문제였습니다. 단순하게 덱을 어떻게 쓸 줄 안다면 쉽게 푸실 수 있는 문제인 것 같습니다. 여기서 여건은 문자열 파싱을 어떻게 하느냐가 제일 중요했던 것 같습니다. 파싱 함수는 인터넷에 돌아다니는 함수를 긁어서 사용했습니다.
#include <iostream>
#include <queue>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
vector<string> split(string str, char delimiter);
int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
int N, M, C;
int input;
string s, num;
vector<string> number;
cin >> C;
for (int i = 0; i < C; i++) {
deque<int> t1;
bool error = false;
cin >> s;
cin >> N;
cin >> num;
num.erase(num.begin());
num.erase(num.end()-1);
number = split(num, ',');
for (string s : number) {
if (atoi(s.c_str())) {
t1.push_back(atoi(s.c_str()));
}
}
bool check = true;
for (char c : s) {
if (c == 'R') {
if (check)
check = false;
else
check = true;
}
else {
if (t1.empty()) {
error = true;
break;
}
if (check)
t1.pop_front();
else
t1.pop_back();
}
}
if(error)
cout << "error";
else if (check) {
cout << "[";
for (int i = 0; i < t1.size(); i++) {
if (i == t1.size()-1)
cout << t1[i];
else
cout << t1[i] << ",";
}
cout << "]";
}
else {
cout << "[";
for (int i = t1.size() - 1; i >= 0; i--) {
if (i == 0)
cout << t1[i];
else
cout << t1[i] << ",";
}
cout << "]";
}
cout << "\n";
}
}
vector<string> split(string input, char delimiter) {
vector<string> answer;
stringstream ss(input);
string temp;
while (getline(ss, temp, delimiter)) {
answer.push_back(temp);
}
return answer;
}
드디어 골드 5 왔네요.. 더 노력해서 플레까지 가보겠습니다.
'자료구조 및 알고리즘 > 문제풀이' 카테고리의 다른 글
백준 C++ 2805번) 나무 자르기 (0) | 2022.08.26 |
---|---|
백준 C++ 1654번) 랜선 자르기 (0) | 2022.08.25 |
백준 C++ 1021번) 회전하는 큐 (0) | 2022.08.24 |
백준 C++ 11866) 오세푸스 문제 0 (0) | 2022.08.23 |
백준 C++2164번) 카드2 (0) | 2022.08.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 드림핵
- 정보보안
- BFS
- 개발
- 링크드 리스트
- 보안
- 멀티쓰레드
- 인제대학교
- 레지스터
- 지뢰찾기
- Select모델
- 시스템보안
- Dreamhack
- 자료구조
- c++
- 학교
- 워셜알고리즘
- 스레드풀
- queue
- 컨퍼런스
- 고양이
- STL
- 알고리즘
- 야경
- 백준
- 더블버퍼링
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 28 | 29 |
30 | 31 |
글 보관함