PS

HackerRank. Simple Text Editor

tose33 2023. 10. 19. 15:34

https://www.hackerrank.com/challenges/one-week-preparation-kit-simple-text-editor/problem?isFullScreen=true&h_l=interview&playlist_slugs%5B%5D=preparation-kits&playlist_slugs%5B%5D=one-week-preparation-kit&playlist_slugs%5B%5D=one-week-day-six

 

Simple Text Editor | HackerRank

Implement a simple text editor and perform some number of operations.

www.hackerrank.com

 

stack<pair<int,string>> st; 에 1,2 연산을 할때 {연산번호, 지우거나 추가한 문자열} 을 저장해 주면 된다.

이렇게 하면 4번 undo 연산을 실행할때, 스택의 top 에 있는 연산이 마지막에 있는 1번or2번 연산이 된다.

append를 undo 하면 반대로 delete 하면 되고, delete 를 undo 하면 append 하면 된다.