※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26535번 문제인 Chicken Pen이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26535
26535번: Chicken Pen
A drawing of the smallest square pen that is large enough to hold all the chickens. The symbol ‘x’ will denote the perimeter of the fence, and a ‘.’ will denote a space for chickens inside the pen.
www.acmicpc.net
한 변의 길이가 L인 정사각형의 넓이가 주어지는 닭의 수보다 작을 동안 L을 0부터 1씩 증가시키면서 필요한 가장 작은 닭장의 크기를 계산하자.
위에서 구한 크기를 기반으로 닭장을 찍는 프로그램을 작성하면 문제를 해결할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long long ll;
ll A, L;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> A;
while (L * L < A) L++;
for (int i = -2; i < L; i++) cout << 'x';
cout << '\n';
for (int i = 0; i < L; i++) {
cout << 'x';
for (int j = 0; j < L; j++) cout << '.';
cout << 'x' << '\n';
}
for (int i = -2; i < L; i++) cout << 'x';
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26564 // C++] Poker Hand (0) | 2022.12.21 |
---|---|
[BOJ 26552 // C++] Zero (0) | 2022.12.21 |
[BOJ 10187 // C++] Golden (0) | 2022.12.21 |
[BOJ 26502 // C++] Decoder (0) | 2022.12.21 |
[BOJ 26536 // C++] Cowspeak (0) | 2022.12.21 |