Skip to content
40 changes: 40 additions & 0 deletions Sikca/M_2024_05/Week_1/P_4928/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

---

## 🔖 문제 설명

- 괄호, 문자, 숫자가 주어지면 그에 맞는 문자열을 출력하는 문제
- `link` : [`click`](https://www.acmicpc.net/problem/4928)

---

## 🍳 스스로 생각한 접근 방식

괄호안에 문자와 숫자가 주어지면 숫자의 개수 만큼 문자를 출력해야 하는데 이와 비슷한 백준 '괄호' 라는 문제를 푼 기억이 있기에 스택을 사용하면 풀릴것 같았다.

---


## ❗ 틀린 이유 설명

문제에서 숨겨진 예외 케이스인 숫자가 연달아 나올때를 처리하지 못했다.

---


## ✅ 올바른 접근 방식 및 해결 방식

숫자가 나올때 까지 스택으로 입력받아 처리했다/

---

## 🛠 자신의 풀이에서 개선할 부분

올바른 풀이 인것 같다.

---

## Reference

---

Binary file added Sikca/M_2024_05/Week_1/P_4928/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions Sikca/M_2024_05/Week_1/P_4928/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <bits/stdc++.h>
#include <ctype.h>
#define sz(x) (int)x.size()
using namespace std;
string a;
stack <char> s;
stack <char> ans;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//확실한 생각과 계획 코드
while(1){
getline(cin,a);
if (a == "$") return 0;
s = {};
for (int i = 0; i < (int)a.size(); i++){
if (a[i] == '('){
s.push('(');
}else if (isdigit(a[i])){
s.push(a[i]);
}else if (isalpha(a[i])){
s.push(a[i]);
}else if (a[i] == ')'){
int len = 0;
string temp;
int k = 1;
len += s.top()-'0';
s.pop();
while(isdigit(s.top())){
len += 10*k * (s.top() -'0');
k *= 10;
s.pop();
}
while(s.top() != '('){
temp += s.top();
s.pop();
}
reverse(temp.begin(),temp.end());
s.pop();

for (int j = 0; j < len; j++){
for (auto w : temp){
s.push(w);
}
}
}
}
while(!s.empty()){
ans.push(s.top());
s.pop();
}
while(!ans.empty()){
cout << ans.top();
ans.pop();
}
cout << '\n';
}
return 0;
}