Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

25-alstjr7437 #190

Merged
merged 2 commits into from
May 22, 2024
Merged

25-alstjr7437 #190

merged 2 commits into from
May 22, 2024

Conversation

alstjr7437
Copy link
Member

@alstjr7437 alstjr7437 commented May 18, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

AC

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

40๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฌธ์ œ๋Š” ๊ฐ„๋‹จํ•ด์„œ ์•„์ด๋””์–ด๋Š” ๋ฐ”๋กœ ๋– ์˜ฌ๋ž์Šต๋‹ˆ๋‹ค!

์ฒ˜์Œ์—๋Š”

  1. deque๋ฅผ ๋งŒ๋“ ๋‹ค
  2. R์ด ์˜ค๋ฉด deque๋ฅผ ๋’ค์ง‘์–ด ๋ฒ„๋ฆฐ๋‹ค
  3. D๊ฐ€ ์˜ค๋ฉด popleft()ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ๋นผ๋ฒ„๋ฆฐ๋‹ค.
  4. ์ถœ๋ ฅํ•œ๋‹ค.




ํ•˜์ง€๋งŒ ๊ณจ๋“œ5 ๋ฌธ์ œ๊ฐ€ ์ด๋ ‡๊ฒŒ ์‰ฝ๊ฒŒ ํ’€๋ฆฐ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด์„œ ์ œ์ถœ์„ ํ–ˆ๋Š”๋ฐ
์—ญ์‹œ ์•„๋ž˜์™€ ๊ฐ™์ด ์‹œ๊ฐ„์ดˆ๊ณผ์˜ ๋Šช์— ๋น ์กŒ์Šต๋‹ˆ๋‹ค.
image

์ž˜ ์ƒ๊ฐํ•ด๋ณด๋ฉด reverse์™€ reversedํ•จ์ˆ˜์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋Š” O(N)์ธ๋ฐ ๋งค๋ฒˆ ๋’ค์ง‘์–ด์ฃผ๋ฉด ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋‚ฉ๋‹ˆ๋‹ค!








๐Ÿ”ฅ ์‹œ๊ฐ„ ์ค„์ด๋Š” ์ฝ”๋“œ

  1. deque๋ฅผ ๋งŒ๋“ ๋‹ค.
  2. R์ด ์˜ค๋ฉด temp_reverse๋ผ๋Š” ๋ณ€์ˆ˜๋ฅผ ๋ณ€๊ฒฝํ•ด์ค€๋‹ค.
  3. D๊ฐ€์˜ค๋ฉด temp_reverse์— ๋”ฐ๋ผ ์™ผ์ชฝ์—์„œ ๋บ„์ง€ ์˜ค๋ฅธ์ชฝ์—์„œ ๋บ„์ง€ ๊ฒฐ์ •ํ•œ๋‹ค.
  4. ๋งˆ์ง€๋ง‰์— temp_reverse๊ฐ€ True๋ฉด ๋’ค์ง‘์–ด์„œ ์ถœ๋ ฅํ•œ๋‹ค.

์ด๋ ‡๊ฒŒ ํ•ด์„œ ์™„์„ฑ์„ ํ–ˆ๋Š”๋ฐ



image





๊ฐ‘์ž๊ธฐ 16%์—์„œ ํ‹€๋ ธ๋‹ค๊ณ  ๊ณ„์† ๋‚˜์˜ค๊ธธ๋ž˜ ํ™•์ธํ•ด๋ณด๋‹ˆ

x = deque(input()[1:-1].split(','))

์—์„œ ์—๋Ÿฌ๊ฐ€ ๋‚ฌ์Šต๋‹ˆ๋‹ค.
๋ฌธ์ œ์—์„  ๊ณต๋ฐฑ์ด ์—†๊ธธ๋ž˜ ์ €๋ ‡๊ฒŒ ํ•ด๋„ ๋˜๋Š”์ค„ ์•Œ์•˜๋Š”๋ฐ


์•„๋ž˜์™€ ๊ฐ™์ด strip์œผ๋กœ ๊ณต๋ฐฑ์„ ์—†์• ๋Š” ์ฝ”๋“œ๋กœ ๋ฐ”๊พธ๋‹ˆ๊นŒ ๋˜๋”๊ตฐ์š”..
์ด๊ฑฐ ์ฐพ๋Š๋ผ๊ณ  ํ•œ 10๋ถ„ ๋ฒ„๋ฆฐ๋“ฏ...

x = deque(input().strip()[1:-1].split(','))




from collections import deque
import sys
input = sys.stdin.readline

t = int(input())

for _ in range(t):
    temp_reverse = False
    error = 0

    p = input()
    n = int(input())
    x = deque(input().strip()[1:-1].split(','))

    # 0์ผ๋•Œ๋Š” ['']์ด ์˜ค๋Š”๊ฑธ ๋ง‰๊ธฐ์œ„ํ•ด ๋น„์›Œ์ค€๋‹ค.
    if n == 0 :
        x = deque()
        
    for i in p:
        # R์ด ์˜ค๋ฉด temp๋ณ€์ˆ˜๋ฅผ ๋ณ€๊ฒฝํ•ด์ค€๋‹ค.
        if i == 'R':
            if temp_reverse :
                temp_reverse = False
            else :
                temp_reverse = True

        # D๊ฐ€ ์˜ค๋ฉด temp ๋ณ€์ˆ˜์— ๋”ฐ๋ผ ์•ž์—์„œ ์‚ญ์ œํ• ์ง€ ๋’ค์—์„œ ์‚ญ์ œํ• ์ง€ ์„ ์ •ํ•œ๋‹ค.
        if i == "D":
            if len(x) == 0:
                error = 1
                break
            else :
                if temp_reverse :
                    x.pop()
                else :
                    x.popleft()
    
    # ๋งˆ์ง€๋ง‰ temp๊ฐ€ true๋ฉด ๋’ค์ง‘์–ด์„œ ์ถœ๋ ฅํ•ด์ค€๋‹ค.
    if temp_reverse :
        x.reverse()

    if error == 0 :
        print(f"[{','.join(str(i) for i in x)}]")
    else : 
        print("error")

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

๋ฑ์ด๋‚˜ ๊ทธ๋Ÿฐ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ž๋ฃŒ๊ตฌ์กฐ ๋ฌธ์ œ์—์„œ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ์ž˜์ƒ๊ฐํ•˜๊ณ  ํ’€์ž!!!

ํ˜น์‹œ ์‹œ๊ฐ„๋ณต์žก๋„ ๊ณ„์‚ฐ์„ ์–ด๋–ป๊ฒŒ ํ•˜๋ฉด๋˜๋‚˜์š”..?
O(N)(์›์†Œ๊ฐฏ์ˆ˜) * O(P)(๋ช…๋ น์–ด R์˜ ๊ฐฏ์ˆ˜)๋กœ ํ•ด์„œ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋‚˜๋Š”๊ฑฐ ๊ฒ ์ฃ ?

@9kyo-hwang
Copy link

์™œ ๋‹ค์‹œ python์œผ๋กœ ๋Œ์•„์˜จ...?

Copy link

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํŒŒ์ด์ฌ ๋ฌธ์ž์—ด ํŒŒ์‹ฑ ์ฒ˜๋ฆฌ ์‰ฌ์šด ๊ฑฐ ๋ถ€๋Ÿฝ๋„ค์š”... ์˜ˆ์ „์— c++๋กœ ํ’€์—ˆ์„ ๋•Œ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌํ•œ๋‹ค๊ณ  ์ฐธ ๊ท€์ฐฎ์•˜์—ˆ๋Š”๋ฐ...

#include <iostream>
#include <string>
#include <queue>
#include <sstream>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);

  int T; cin >> T;

  while(T--) {
    string p; cin >> p;
    int n; cin >> n;
    string arr; cin >> arr;

    deque<int> dq;
    string new_arr = string(arr.begin() + 1, arr.end() - 1);
    istringstream ss(new_arr);
    string buffer;
    while(getline(ss, buffer, ','))
      dq.emplace_back(stoi(buffer));

    bool reverse = false;
    bool error = false;
    for(const auto& ch : p) {
      if(ch == 'R') {
        reverse = !reverse;
      } else if(ch == 'D') {
        if(dq.empty()) {
          cout << "error\n";
          error = true;
          break;
        } else {
          reverse ? dq.pop_back() : dq.pop_front();
        }
      }
    }

    if(error)
      continue;

    cout << "[";
    if(!dq.empty()) {
      int end;
      if(reverse) {
        end = dq.front();
        dq.pop_front();
        while(!dq.empty()) {
          cout << dq.back() << ",";
          dq.pop_back();
        }
      } else {
        end = dq.back();
        dq.pop_back();
        while(!dq.empty()) {
          cout << dq.front() << ",";
          dq.pop_front();
        }
      }
      cout << end;
    }
    cout << "]\n";
  }

  return 0;
}


p = input()
n = int(input())
x = deque(input().strip()[1:-1].split(','))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n์ด 0์ธ ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋งŒ ํ•ด์ฃผ๋ฉด, ๊ตณ์ด strip()์„ ์•ˆ๋ถ™์—ฌ๋„ ๋˜๊ธด ํ•ฉ๋‹ˆ๋‹ค :)

if n == 0:
    input()  # ํ•ด๋‹น ์ž…๋ ฅ์€ ๋ฒ„๋ฆผ
    x = deque()
else:
    x = deque(list(input()[1:-2].split(',')))

# ๋˜๋Š”

try:
    # n == 0์ธ ์ž…๋ ฅ์ด ์ฃผ์–ด์ง„ ๊ฒฝ์šฐ, ๋นˆ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด int๋กœ mapping ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์—๋Ÿฌ ๋ฐœ์ƒ
    x = deque(map(int, input()[1:-2].split(',')))
except: 
    x = deque()  # ์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ empty deque์„ ๋Œ€์ž…

Comment on lines +20 to +23
if temp_reverse :
temp_reverse = False
else :
temp_reverse = True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xor์„ ์ด์šฉํ•ด ๊น”๋”ํ•˜๊ฒŒ ํ•œ ์ค„๋กœ ์ค„์—ฌ๋ด…์‹œ๋‹ค

temp_reverse ^= True

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ€๋…์„ฑ์ด ์˜คํžˆ๋ ค ์ค„์ง€ ์•Š์„๊นŒ์š”..?

Copy link
Collaborator

@H0ngJu H0ngJu May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐ”๋กœ python temp_reverse = not tmp_reverse๋ฅผ ํ•˜๋Š”๊ฒƒ๋„?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐ”๋กœ temp_reverse = not tmp_reverse๋ฅผ ํ•˜๋Š”๊ฒƒ๋„?!

๋™์˜ํ•ฉ๋‹ˆ๋‹ค...!

Comment on lines +35 to +41
if temp_reverse :
x.reverse()

if error == 0 :
print(f"[{','.join(str(i) for i in x)}]")
else :
print("error")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—๋Ÿฌ์— ๋Œ€ํ•œ ์ถœ๋ ฅ ์ฒ˜๋ฆฌ๋ฅผ ์œ„๋กœ ์˜ฌ๋ ค๋ฒ„๋ฆฌ๋Š” ๊ฒŒ ๋” ๊น”๋”ํ•  ๊ฒƒ ๊ฐ™๋„ค์š”.
๋˜, ์–ด์ฐจํ”ผ ๋ฑ์— ๋“ค์–ด์žˆ๋Š” ์›์†Œ๋“ค์ด ๋ฌธ์ž์ด๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์ด๋ ‰ํŠธ๋กœ ๋ฌธ์ž์—ด join ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

if error:
    print('error')
    continue

if temp_reverse:
    x.reverse()

print(f"[{','.join(x)}]")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wkdghdwns199 ๋™์˜ํ•ฉ๋‹ˆ๋‹ค~~~~~~~~~~~ ๋ณด๊ฐํ•ฉ๋‹ˆ๋‹ค~~~~~~~~

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wkdghdwns199 ๋™์˜ํ•ฉ๋‹ˆ๋‹ค~~~~~~~~~~~ ๋ณด๊ฐํ•ฉ๋‹ˆ๋‹ค~~~~~~~~

์™€์ด ํ™์ค€jang...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•— ์‹ค์ˆ˜ ใ…‹ใ…‹ใ…‹

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from collections import deque
import sys

def input(): return sys.stdin.readline().rstrip()

T = int(input())
for _ in range(T):
    queries = deque(input())
    n = int(input())

    numbers = deque(input().strip("[").strip("]").replace(",", " ").split())
    
    reverse = False
    while queries:
        now_query = queries.popleft()
        
        if now_query == "R": reverse = not reverse
        
        elif now_query == "D" and len(numbers) >= 1:
            if reverse: numbers.pop()
            else: numbers.popleft()
        
        else:
            print("error", end="")
            break

    else:
        print("[", end="")
        if reverse: print(",".join(reversed(numbers)), end="")
        else: print(",".join(numbers), end="")
        print("]", end="")
        
    print()

๋ฌธ์ œ ๋ณด์ž๋งˆ์ž ๋ฐ”๋กœ ํ’€์ด ๋– ์˜ฌ๋ ธ๊ณ 

๋ฐ”๋กœ ์Š›ํ–ˆ๋Š”๋ฐ

๋ฐ”๋กœ ๊ณจ์ธ ํ‚คํ‚คํ‚คํ‚คํ‚ผ

์˜ค์˜ˆ~~~~~~~~~~~~~~~~~~~~~~~~

ํž๋งํ–ˆ์”๋‹ˆ๋‹ค.


p = input()
n = int(input())
x = deque(input().strip()[1:-1].split(','))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ—‰ ์ด๋Ÿฐ ๋ฐฉ๋ฒ•์ด................................

Comment on lines +35 to +41
if temp_reverse :
x.reverse()

if error == 0 :
print(f"[{','.join(str(i) for i in x)}]")
else :
print("error")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wkdghdwns199 ๋™์˜ํ•ฉ๋‹ˆ๋‹ค~~~~~~~~~~~ ๋ณด๊ฐํ•ฉ๋‹ˆ๋‹ค~~~~~~~~

@tgyuuAn
Copy link
Member

tgyuuAn commented May 18, 2024

ํŒŒ์ด์ฌ ๋ฌธ์ž์—ด ํŒŒ์‹ฑ ์ฒ˜๋ฆฌ ์‰ฌ์šด ๊ฑฐ ๋ถ€๋Ÿฝ๋„ค์š”... ์˜ˆ์ „์— c++๋กœ ํ’€์—ˆ์„ ๋•Œ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌํ•œ๋‹ค๊ณ  ์ฐธ ๊ท€์ฐฎ์•˜์—ˆ๋Š”๋ฐ...

#include <iostream>
#include <string>
#include <queue>
#include <sstream>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);

  int T; cin >> T;

  while(T--) {
    string p; cin >> p;
    int n; cin >> n;
    string arr; cin >> arr;

    deque<int> dq;
    string new_arr = string(arr.begin() + 1, arr.end() - 1);
    istringstream ss(new_arr);
    string buffer;
    while(getline(ss, buffer, ','))
      dq.emplace_back(stoi(buffer));

    bool reverse = false;
    bool error = false;
    for(const auto& ch : p) {
      if(ch == 'R') {
        reverse = !reverse;
      } else if(ch == 'D') {
        if(dq.empty()) {
          cout << "error\n";
          error = true;
          break;
        } else {
          reverse ? dq.pop_back() : dq.pop_front();
        }
      }
    }

    if(error)
      continue;

    cout << "[";
    if(!dq.empty()) {
      int end;
      if(reverse) {
        end = dq.front();
        dq.pop_front();
        while(!dq.empty()) {
          cout << dq.back() << ",";
          dq.pop_back();
        }
      } else {
        end = dq.back();
        dq.pop_back();
        while(!dq.empty()) {
          cout << dq.front() << ",";
          dq.pop_front();
        }
      }
      cout << end;
    }
    cout << "]\n";
  }

  return 0;
}

์™€ ์–ธ์–ด ์ฐจ์ด ์ฝ”๋“œ ๊ธธ์ด ์ฐจ์ด ๋Œ€๋ฐ• ใ…‹ใ…‹

Copy link
Collaborator

@SeongHoonC SeongHoonC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋„ isReverse ๋ณ€์ˆ˜ ๋งŒ๋“ค์–ด ์•ž์—์„œ ๋นผ๊ณ  ๋’ค์—์„œ ๋นผ๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค! ๋ฐฉ๋ฒ•์€ ๋˜‘๊ฐ™์•„์š”. ๊ทผ๋ฐ ํ”„๋ฆฐํŠธ ์‹œ๊ฐ„์ดˆ๊ณผ ๋•Œ๋ฌธ์— BufferedWrite ๋ฅผ ์‚ฌ์šฉํ•ด ๋ฌธ์ž๋ฅผ ๋‹ค ์ถ”๊ฐ€ํ•˜๊ณ  flush ํ–ˆ์Šต๋‹ˆ๋‹ค..!
0 ๋ถ„๊ธฐ ๋•Œ๋ฌธ์— ์‹คํŒจํ•œ๊ฑฐ ํ‚น๋ฐ›๋„ค์š”.

image
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter

private lateinit var br: BufferedReader
private lateinit var bw: BufferedWriter

fun main() {
    br = BufferedReader(InputStreamReader(System.`in`))
    bw = BufferedWriter(OutputStreamWriter(System.out))
    val t = br.readLine().toInt()
    repeat(t) {
        ac()
    }
}

fun ac() {
    val instruction = br.readLine().chunked(1)
    val n = br.readLine().toInt()
    val input = br.readLine()
    val queue = ArrayDeque<Int>()

    if (n != 0) {
        input.substring(1, input.length - 1).split(",").forEach { queue.add(it.toInt()) }
    }

    var isReversed = false
    for (i in instruction.indices) {
        when {
            !isReversed && instruction[i] == "R" -> isReversed = true
            isReversed && instruction[i] == "R" -> isReversed = false
            instruction[i] == "D" -> {
                if (queue.isEmpty()) {
                    println("error")
                    return
                }
                if (isReversed) {
                    queue.removeLast()
                    continue
                }
                queue.removeFirst()
            }
        }
    }
    printQueue(queue, isReversed)
}

private fun printQueue(queue: ArrayDeque<Int>, isReversed: Boolean) {
    bw.write("[")
    while (queue.isNotEmpty()) {
        bw.write("${if (isReversed) queue.removeLast() else queue.removeFirst()}")
        if (queue.isEmpty()) {
            break
        }
        bw.write(",")
    }
    bw.write("]")
    bw.newLine()
    bw.flush()
}

Comment on lines +20 to +23
if temp_reverse :
temp_reverse = False
else :
temp_reverse = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ€๋…์„ฑ์ด ์˜คํžˆ๋ ค ์ค„์ง€ ์•Š์„๊นŒ์š”..?

Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฏผ์„๋‹˜ PR๊ณผ ๋˜‘๊ฐ™์€ ๊ณผ์ •์„ ๊ฒช์—ˆ๋„ค์š”

  1. R์ด ๋“ค์–ด์˜ฌ๋•Œ reverse๋ฅผ ํ•˜๋„๋ก ํ–ˆ๋”๋‹ˆ ๋˜‘๊ฐ™์ด ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋‚ฌ์Šต๋‹ˆ๋‹ค

์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ• ๊นŒ ํ•˜๋‹ค๊ฐ€ ๋”ฐ๋กœ reverse์— ๋Œ€ํ•œ flag ์‹ ํ˜ธ๋ฅผ ๋‘๊ณ , T/F๋กœ ๋ฐ”๊พธ๋„๋ก ํ•ด์„œ ๋งˆ์ง€๋ง‰ ์ถœ๋ ฅํ•˜๊ธฐ ์ „์— ํ•œ๋ฒˆ๋งŒ reverse๊ฐ€ ๋˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ deque์—์„œ ๋นผ๋Š” ๊ฒƒ๋„ reverse_check์ด True์ด๋ฉด pop()์„ ํ•ด์ฃผ์—ˆ์–ด์š”

์ค‘๊ฐ„์— error์ผ๋•Œ break์„ ๋นผ๋จน์–ด์„œ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค๊ฐ€ ๋ช‡๋ฒˆ ๋‚˜์™”๋„ค์š” ํ—ˆํ—ˆ
์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค ~~~

image

import sys
from collections import deque

def input(): return sys.stdin.readline().rstrip()

T = int(input())

for _ in range(T):
    p = input()
    n = int(input())
    arr = deque(input().strip("[").strip("]").replace(",", " ").split())
    reverse_check = False
    error_check = 0

    for i in range(len(p)):
        if p[i] == "R":
            #arr.reverse()
            reverse_check = not reverse_check
        else:
            if len(arr) !=  0:
                if reverse_check: # reverse๋ฉด ์•ž ์›์†Œ๊ฐ€ ์•„๋‹ˆ๋ผ ๋’ค ์›์†Œ๋ฅผ ์ œ๊ฑฐ
                    arr.pop()
                else:
                    arr.popleft()
            else:
                error_check = 1
                print("error")
                break

    if not error_check:
        if reverse_check:
            arr.reverse()
        print("[" + ",".join(arr) + "]")

Comment on lines +20 to +23
if temp_reverse :
temp_reverse = False
else :
temp_reverse = True
Copy link
Collaborator

@H0ngJu H0ngJu May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐ”๋กœ python temp_reverse = not tmp_reverse๋ฅผ ํ•˜๋Š”๊ฒƒ๋„?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants