※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 11287번 문제인 Margaret’s Minute Minute Manipulation이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/11287
11287번: Margaret’s Minute Minute Manipulation
Margaret has always been a good maths student. She has been trying to apply the principles of binary quantum refraction to time travel in her free time. By encoding time in a binary format and adding a non negative time difference, δ, she is hoping to cre
www.acmicpc.net
주어지는 표 형태의 시간으로부터, 표의 각 열을 이진수를 십진수로 변환하는 것으로 HH:MM:SS의 각 자리를 구할 수 있다. HH:MM:SS 형태의 시간을 다시 초단위로 바꿔 저장해 문제에서 요구하는 시각 T+δ를 찾아내고, 이를 주어지는 표 형태로 다시 돌려놓는 것으로 문제를 해결하자.
올바른 시간 표기는 00:00:00부터 23:59:59까지임에 유의하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int T, D, TD;
int H, M, S;
int table[4][6];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int r = 0; r < 4; r++) {
for (int c = 0; c < 6; c++) {
cin >> table[r][c];
}
}
T += (table[0][0] * 8 + table[1][0] * 4 + table[2][0] * 2 + table[3][0]) * 36000;
T += (table[0][1] * 8 + table[1][1] * 4 + table[2][1] * 2 + table[3][1]) * 3600;
T += (table[0][2] * 8 + table[1][2] * 4 + table[2][2] * 2 + table[3][2]) * 600;
T += (table[0][3] * 8 + table[1][3] * 4 + table[2][3] * 2 + table[3][3]) * 60;
T += (table[0][4] * 8 + table[1][4] * 4 + table[2][4] * 2 + table[3][4]) * 10;
T += (table[0][5] * 8 + table[1][5] * 4 + table[2][5] * 2 + table[3][5]) * 1;
for (int r = 0; r < 4; r++) {
for (int c = 0; c < 6; c++) {
cin >> table[r][c];
}
}
D += (table[0][0] * 8 + table[1][0] * 4 + table[2][0] * 2 + table[3][0]) * 36000;
D += (table[0][1] * 8 + table[1][1] * 4 + table[2][1] * 2 + table[3][1]) * 3600;
D += (table[0][2] * 8 + table[1][2] * 4 + table[2][2] * 2 + table[3][2]) * 600;
D += (table[0][3] * 8 + table[1][3] * 4 + table[2][3] * 2 + table[3][3]) * 60;
D += (table[0][4] * 8 + table[1][4] * 4 + table[2][4] * 2 + table[3][4]) * 10;
D += (table[0][5] * 8 + table[1][5] * 4 + table[2][5] * 2 + table[3][5]) * 1;
TD = T + D;
if (TD >= 86400) TD -= 86400;
H = TD / 3600; TD %= 3600;
M = TD / 60; TD %= 60;
S = TD;
int cur = H / 10; H %= 10;
for (int i = 3; i > -1; i--) {
table[i][0] = cur & 1;
cur >>= 1;
}
cur = H;
for (int i = 3; i > -1; i--) {
table[i][1] = cur & 1;
cur >>= 1;
}
cur = M / 10; M %= 10;
for (int i = 3; i > -1; i--) {
table[i][2] = cur & 1;
cur >>= 1;
}
cur = M;
for (int i = 3; i > -1; i--) {
table[i][3] = cur & 1;
cur >>= 1;
}
cur = S / 10; S %= 10;
for (int i = 3; i > -1; i--) {
table[i][4] = cur & 1;
cur >>= 1;
}
cur = S;
for (int i = 3; i > -1; i--) {
table[i][5] = cur & 1;
cur >>= 1;
}
for (int r = 0; r < 4; r++) {
for (int c = 0; c < 6; c++) {
cout << table[r][c] << ' ';
}
cout << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26314 // C++] Vowel Count (0) | 2022.12.13 |
---|---|
[BOJ 11290 // C++] Wonowon (0) | 2022.12.13 |
[BOJ 11288 // C++] Ether's Encryption (0) | 2022.12.13 |
[BOJ 26307 // C++] Correct (0) | 2022.12.13 |
[BOJ 5212 // C++] 지구 온난화 (0) | 2022.12.13 |