백준 5397 키로거 c++
[문제 링크]
https://www.acmicpc.net/problem/5397
[입출력 예]
입력 | 출력 |
---|---|
2 <<BP<A>>Cd- ThisIsIsS3Cr3t |
BAPC ThisIsIsS3Cr3t |
[소스코드]
#include <iostream> #include <string> #include <list> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; while(n--){ string s; cin>>s; list <char> L; auto cursor = L.end(); for (auto c:s){ if(c=='<'){ if (cursor!=L.begin()){ cursor--; } } else if(c=='>'){ if (cursor!=L.end()){ cursor++; } } else if (c=='-'){ if (cursor!=L.begin()){ cursor--; cursor=L.erase(cursor); } } else { L.insert(cursor,c); } } for (auto c:L){ cout<<c; } cout<<'\n'; } return 0; }
'PS > BOJ' 카테고리의 다른 글
백준 6918 옥상 정원 꾸미기 c++ (0) | 2022.01.13 |
---|---|
백준 1874 스택수열 c++ (0) | 2022.01.08 |
백준 2493 탑 c++ (0) | 2022.01.08 |
백준 2003 수들의 합 2 (c++) (0) | 2022.01.04 |
백준 3425 - 고스택 파이썬 풀이 (0) | 2021.12.08 |
댓글
이 글 공유하기
다른 글
-
백준 1874 스택수열 c++
백준 1874 스택수열 c++
2022.01.08 -
백준 2493 탑 c++
백준 2493 탑 c++
2022.01.08 -
백준 2003 수들의 합 2 (c++)
백준 2003 수들의 합 2 (c++)
2022.01.04 -
백준 3425 - 고스택 파이썬 풀이
백준 3425 - 고스택 파이썬 풀이
2021.12.08
댓글을 사용할 수 없습니다.