Skip to content

Commit

Permalink
Merge pull request #11 from AlgoLeadMe/3-oesnuj
Browse files Browse the repository at this point in the history
3-oesnuj
  • Loading branch information
oesnuj authored Apr 10, 2024
2 parents b3b69ee + 62cd274 commit 88eee6e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
|:----:|:---------:|:----:|:-----:|:----:|
| 1์ฐจ์‹œ | 2024.03.26 | ์Šคํƒ | [ํ›„์œ„ํ‘œ๊ธฐ์‹2](https://www.acmicpc.net/problem/1935) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/4) |
| 2์ฐจ์‹œ | 2024.03.29 | ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ | [์—๋””ํ„ฐ](https://www.acmicpc.net/problem/1406) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/8) |
| 3์ฐจ์‹œ | 2024.04.02 | ๋ฑ | [์นด๋“œ ๋†“๊ธฐ](https://www.acmicpc.net/problem/18115) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/11) |
---
51 changes: 51 additions & 0 deletions oesnuj/๋ฑ/18115.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
deque <int> d;
vector <int > v;
int n;
cin >> n;
for (int i = 0; i < n; i++) { //๊ทœ์น™ ์ €์žฅํ•˜๊ธฐ : ์‚ฌ์šฉํ•œ ์ˆœ์„œ๋Œ€๋กœ vector์— ๋„ฃ์Œ
int num;
cin >> num;
v.push_back(num);
}
vector<int>::reverse_iterator rit = v.rbegin(); //๋ณต์›์‹œ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์— ์‚ฌ์šฉํ•œ ๊ทœ์น™๋ถ€ํ„ฐ ์‚ฌ์šฉํ•ด์•ผํ•˜๊ธฐ์— ์—ญ๋ฐ˜๋ณต์ž ์‚ฌ์šฉ

int card = 1; //๋‹ค ๋‚ด๋ ค๋†“์€ ์ดํ›„ ํ˜„์žฌ ์ œ์ผ ์œ„์˜ ์นด๋“œ๋Š” 1
for (rit; rit != v.rend(); rit++) {
//๊ทœ์น™ 1์€ ์ œ์ผ ์œ„ ์นด๋“œ 1์žฅ ๋ฐ”๋‹ฅ์— ๋‚ด๋ ค๋†“๊ธฐ์ด๋ฏ€๋กœ ๋ณต์›์‹œ์—๋Š” ๋ฑ์˜ ๊ฐ€์žฅ ์œ„๋กœ ์˜ฎ๊ธด๋‹ค.
if (*rit == 1)
d.push_back(card);


// ๊ทœ์น™ 2๋Š” ์œ„์— ๋‘๋ฒˆ์งธ ์นด๋“œ ๋ฐ”๋‹ฅ์— ๋‚ด๋ ค๋†“๊ธฐ์ด๋ฏ€๋กœ ๋ณต์›์‹œ์—๋Š” ๋ฑ์˜ ์œ„์—์„œ ๋‘๋ฒˆ์งธ๋กœ ์˜ฎ๊ธด๋‹ค.
else if (*rit == 2)
{
int temp = d.back(); //๊ฐ€์žฅ ์œ„์˜ ์ˆซ์ž๋Š” ์ž ๊น ๋นผ๊ณ 
d.pop_back();
d.push_back(card); //๋„ฃ์–ด์•ผํ•  ์นด๋“œ ๋„ฃ๊ณ 
d.push_back(temp); //๋นผ๋‘์—ˆ๋˜ ๊ฐ€์žฅ ์œ„์˜ ์ˆซ์ž ๋‹ค์‹œ ๋„ฃ๊ธฐ
}

//๊ทœ์น™ 3์€ ์ œ์ผ ๋ฐ‘์˜ ์นด๋“œ๋ฅผ ๋ฐ”๋‹ฅ์œผ๋กœ ๋‚ด๋ ค๋†“๊ธฐ์ด๋ฏ€๋กœ ๋ณต์›์‹œ์—๋Š” ๋ฑ์˜ ์ œ์ผ ๋ฐ‘์œผ๋กœ ์˜ฎ๊ธด๋‹ค.
else if (*rit == 3)
d.push_front(card);

card++; //๋‹ค์Œ์นด๋“œ๋ฅผ ๋ณต์›์‹œ์ผœ์•ผํ•จ(๋‹ค์Œ์นด๋“œ๋Š” ํ•˜๋‚˜ ํฐ ์ˆซ์ž์ž„)
}

reverse(d.begin(), d.end()); //๋ฑ์˜ ์š”์†Œ๋ฅผ ๋’ค(์œ„)์—์„œ ๋ถ€ํ„ฐ ์ถœ๋ ฅํ•ด์•ผํ•ด ๋’ค์ง‘๋Š”๋‹ค.
for (auto &k : d) { //์ถœ๋ ฅ
cout << k << " ";
}
return 0;
}

0 comments on commit 88eee6e

Please sign in to comment.