-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sohyundoh
committed
Mar 17, 2022
1 parent
6ac5241
commit 63e8c47
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
#include <queue> | ||
#include <algorithm> | ||
using namespace std; | ||
int main() { //1부터 N까지 Queue에 저장한 다음 K-1번 앞에 있는 걸 뒤에 붙이고 pop한다. | ||
int N, K; | ||
cin >> N >> K; | ||
queue<int> q; | ||
for (int i = 0; i < N; i++) { | ||
q.push(i + 1); | ||
} | ||
cout << "<"; | ||
while (!q.empty()) { | ||
for (int i = 0; i < K - 1; i++) { | ||
q.push(q.front());//front 요소를 push | ||
q.pop();//push한 요소를 front에서 pop | ||
} | ||
cout << q.front(); | ||
q.pop(); | ||
if (!q.empty()) { | ||
cout << ", "; | ||
} | ||
} | ||
cout << ">"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <iostream> | ||
#include <deque> | ||
#include <vector> | ||
#include <algorithm> | ||
using namespace std; | ||
int main() { | ||
int N; | ||
cin >> N; | ||
deque<int> d; //기술은 뒤에서 빼야하고 남은 카드는 뒤, 앞 모두 壺峠球퓐 deque을 사용 | ||
deque<int> l; | ||
for (int i = 0; i < N; i++) { | ||
int a; | ||
cin >> a; | ||
d.push_back(a); | ||
} | ||
for (int i = 0; i < N; i++) { | ||
if (d.back() == 1) { | ||
l.push_front(i + 1); | ||
} | ||
else if (d.back() == 2) {//2번 기술일 경우 두번째에 넣어야하므로 첫번째를 빼고 다시 넣어줌 | ||
int temp = l.front(); | ||
l.pop_front(); | ||
l.push_front(i + 1); | ||
l.push_front(temp); | ||
} | ||
else if (d.back() == 3) { | ||
l.push_back(i + 1); | ||
} | ||
d.pop_back(); | ||
} | ||
while (!l.empty()) { | ||
cout << l.front() << " "; | ||
l.pop_front(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <iostream> | ||
#include <stack> | ||
using namespace std; | ||
int main() { | ||
//괄호가 닫히는 순간 더해줘야한다. | ||
string s; | ||
int answer = 0, temp; | ||
cin >> s; | ||
bool check = true;//괄호가 올바른 것인지 체크 | ||
temp = 1;//열린 괄호를 계산해 주기 위해 | ||
stack<char> c;//괄호 저장할 stack | ||
for (int i = 0; i < s.length(); i++) { | ||
if (s[i] == '(') { | ||
//값에 2를 곱해줘야함 | ||
temp *= 2; | ||
c.push('('); | ||
} | ||
else if (s[i] == ')') { | ||
if (c.empty() || c.top() != '(') { | ||
//닫힌 괄호가 들어왔을 때 만일 stack이 비어있다면 올바른 괄호가 아님 | ||
check = false; | ||
break; | ||
} | ||
else { | ||
//만일 이 바로 이전에 열린괄호를 닫는 거라면 answer에 2를 더해주고 다시 temp를 수정 | ||
if (s[i - 1] == '(') { | ||
answer += temp; | ||
} | ||
temp /= 2; | ||
c.pop(); | ||
} | ||
} | ||
else if (s[i] == '[') { | ||
//*3을 해주고 answer에 더해줘야함. | ||
temp *= 3; | ||
c.push('['); | ||
} | ||
else if (s[i] == ']') { | ||
if (c.empty() || c.top() != '[') { | ||
//닫힌 괄호가 들어왔을 때 만일 stack이 비어있다면 올바른 괄호가 아님 | ||
check = false; | ||
break; | ||
} | ||
else { | ||
//만일 이 바로 이전에 열린괄호를 닫는 거라면 answer에 2를 더해주고 다시 temp를 수정 | ||
if (s[i - 1] == '[') { | ||
answer += temp; | ||
} | ||
temp /= 3; | ||
c.pop(); | ||
} | ||
} | ||
} | ||
if (check && c.empty()) { | ||
cout << answer; | ||
} | ||
else { | ||
cout << 0; | ||
} | ||
return 0; | ||
} |