Skip to content

Commit 823d4d4

Browse files
committed
update
1 parent 197f727 commit 823d4d4

File tree

5 files changed

+89
-4
lines changed

5 files changed

+89
-4
lines changed

lecture1/lecture1/ex054.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ void ex054() {
2727
}
2828
}
2929

30-
int main() {
31-
ex054();
32-
std::cout << "done!" << std::endl;
33-
}
30+
//int main() {
31+
// ex054();
32+
// std::cout << "done!" << std::endl;
33+
//}
3434
//NO
3535
//YES

lecture1/lecture1/ex055.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <chrono>
4+
#include <string>
5+
#include <algorithm>
6+
#include <stack>
7+
using namespace std;
8+
using namespace chrono;
9+
10+
// 기차운행 (스택 자료구조 응용)
11+
12+
void ex055() {
13+
14+
vector<int> trains{ 2, 1, 3, 4 };
15+
stack<int> st;
16+
vector<string> res;
17+
int pos = 0;
18+
int order = 1;
19+
bool possible = true;
20+
while (order != trains.size()+1) {
21+
if (!st.empty()) {
22+
if (st.top() != order) {
23+
if (pos == trains.size()) {
24+
possible = false;
25+
break;
26+
}
27+
st.push(trains[pos]);
28+
res.push_back("P");
29+
pos++;
30+
}
31+
else {
32+
res.push_back("O");
33+
order++;
34+
st.pop();
35+
}
36+
}
37+
else {
38+
res.push_back("P");
39+
st.push(trains[pos]);
40+
pos++;
41+
}
42+
}
43+
if (possible) {
44+
for (int i = 0; i < res.size(); i++) {
45+
cout << res[i];
46+
}
47+
}
48+
else
49+
cout << "impossible";
50+
51+
}
52+
53+
//int main() {
54+
// ex055();
55+
// cout << endl << "done!" << endl;
56+
//}
57+
//PPOOPOPO

lecture1/lecture1/ex056.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string>
4+
#include <stack>
5+
using namespace std;
6+
7+
// Àç±ÍÇÔ¼ö ºÐ¼®
8+
9+
void ex056() {
10+
int n = 3;
11+
12+
13+
14+
}
15+
16+
int main() {
17+
ex056();
18+
cout << endl << "done!" << endl;
19+
}
20+
//

lecture1/lecture1/lecture1.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@
177177
<ClCompile Include="ex052.cpp" />
178178
<ClCompile Include="ex053.cpp" />
179179
<ClCompile Include="ex054.cpp" />
180+
<ClCompile Include="ex055.cpp" />
181+
<ClCompile Include="ex056.cpp" />
180182
</ItemGroup>
181183
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
182184
<ImportGroup Label="ExtensionTargets">

lecture1/lecture1/lecture1.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,11 @@
177177
<ClCompile Include="ex054.cpp">
178178
<Filter>소스 파일</Filter>
179179
</ClCompile>
180+
<ClCompile Include="ex055.cpp">
181+
<Filter>소스 파일</Filter>
182+
</ClCompile>
183+
<ClCompile Include="ex056.cpp">
184+
<Filter>소스 파일</Filter>
185+
</ClCompile>
180186
</ItemGroup>
181187
</Project>

0 commit comments

Comments
 (0)