※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 10195번 문제인 Underwater Trip이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/10195
10195번: Underwater Trip
The first line in the test data file contains the number of test cases. Each test case begins with a description of the depth and length of the tunnel. After that is the number of stalagmites, followed by the size and distance of each stalagmite on a separ
www.acmicpc.net
잠수정이 움직일 때마다(즉 1초 단위로) 현재 잠수정이 터널의 천장, 바닥 또는 stalagmite와 충돌했는지의 여부를 계산해 문제를 해결하자. stalagmite와의 충돌 여부는 잠수정이 위치한 행과 stalagmite의 높이의 합과 터널의 높이의 값을 적절하게 비교하는 것으로 판단할 수 있다.
이 문제의 경우 주어지는 입력에 문제 해결에 필요하지 않은 문자열이 많이 포함되어 있다. 글쓴이는 이러한 문자열들을 대충 받아넘길 xx 변수를 만들어 필요없는 입력을 전부 xx로 받는 식으로 코드를 작성했다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <vector>
using namespace std;
int T;
int R, C, stal, seq, tall, dist;
string xx;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
for (int t = 1; t <= T; t++) {
cout << "Case: " << t << '\n';
cin >> xx >> xx >> R >> xx >> C >> stal >> xx;
vector<int> stalagmite(C + 1);
while (stal--) {
cin >> tall >> xx >> xx >> dist >> xx >> xx;
stalagmite[dist] = max(stalagmite[dist], tall);
}
cin>> seq >> xx;
while (seq--) {
bool chk = 1;
string s; cin >> s;
int r = 0, c = 0;
for (auto& l : s) {
c++;
if (l == 'v') r++;
else if (l == '^') r--;
if (r < 0) {
cout << "Sequence " << s << " Crashed into tunnel ceiling\n";
chk = 0;
break;
}
else if (r >= R) {
cout << "Sequence " << s << " Crashed into tunnel floor\n";
chk = 0;
break;
}
else if (r + 1 + stalagmite[c] > R) {
cout << "Sequence " << s << " Crashed into stalagmite\n";
chk = 0;
break;
}
}
if (chk) cout << "Sequence " << s << " Reached end of tunnel\n";
}
}
}
'BOJ' 카테고리의 다른 글
[BOJ 10193 // C++] Word Swap (1) | 2023.12.11 |
---|---|
[BOJ 13322 // C++] 접두사 배열 (0) | 2023.12.10 |
[BOJ 10194 // C++] Aligned Calender (0) | 2023.12.08 |
[BOJ 28214 // C++] 크림빵 (0) | 2023.12.07 |
[BOJ 17103 // C++] 골드바흐 파티션 (1) | 2023.12.06 |