Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 스택
- XR Interaction Toolkit
- 트리
- 다이나믹 프로그래밍
- 백준
- 자료구조
- 재귀
- 다익스트라
- 유니온 파인드
- c++
- 우선순위 큐
- 정렬
- VR
- 시뮬레이션
- 그래프
- 백트래킹
- Team Fortress 2
- 구현
- Unreal Engine 5
- 브루트포스
- 수학
- 알고리즘
- 그리디 알고리즘
- 투 포인터
- DFS
- 문자열
- BFS
- 유니티
- ue5
- 누적 합
Archives
- Today
- Total
1일1알
백준 5397번 키로거 C++ 본문
https://www.acmicpc.net/problem/5397
5397번: 키로거
첫째 줄에 테스트 케이스의 개수가 주어진다. 각 테스트 케이스는 한줄로 이루어져 있고, 강산이가 입력한 순서대로 길이가 L인 문자열이 주어진다. (1 ≤ L ≤ 1,000,000) 강산이가 백스페이스를 입
www.acmicpc.net
연결 리스트를 이용하였다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int t;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
while (t--) {
list<char> lst;
auto cursor = lst.end();
string str;
cin >> str;
for (int i = 0; i < str.length(); i++) {
char currChar = str[i];
if (currChar == '<') {
if (cursor == lst.begin()) continue;
--cursor;
}
else if (currChar == '>') {
if (cursor == lst.end()) continue;
++cursor;
}
else if (currChar == '-') {
if (cursor == lst.begin()) continue;
cursor = lst.erase(--cursor);
}
else {
cursor = lst.insert(cursor, currChar);
++cursor;
}
}
for (auto a : lst) {
cout << a;
}
cout << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 10974번 모든 순열 C++ (0) | 2022.10.11 |
---|---|
백준 2056번 작업 C++ (0) | 2022.10.10 |
백준 1699번 제곱수의 합 C++ (0) | 2022.10.08 |
백준 17822번 원판 돌리기 C++ (0) | 2022.10.04 |
백준 2212번 센서 C++ (1) | 2022.10.03 |