[백준 23810] 골뱅이 찍기 - 뒤집힌 ㅋ (C#, C++) - soo:bak
작성일 :
문제 링크
설명
뒤집힌 ㅋ자 모양의 골뱅이 패턴을 출력하는 문제입니다.
접근법
전체 크기는 5n x 5n이 됩니다.
위쪽 가로줄은 첫 n줄, 가운데 가로줄은 2n번째부터 3n번째 행 직전까지입니다.
왼쪽 세로줄은 열 인덱스가 n 미만인 경우입니다.
이후, 위 조건 중 하나라도 만족하면 골뱅이를 출력하고, 그 외에는 출력하지 않습니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using System.Text;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine()!);
var sb = new StringBuilder();
for (var i = 0; i < 5 * n; i++) {
for (var j = 0; j < 5 * n; j++) {
if (i < n) sb.Append('@');
else if (i > 2 * n - 1 && i < 3 * n) sb.Append('@');
else if (j < n) sb.Append('@');
}
sb.Append('\n');
}
Console.Write(sb.ToString());
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
if (!(cin >> n)) return 0;
for (int i = 0; i < 5 * n; i++) {
for (int j = 0; j < 5 * n; j++) {
if (i < n) cout << "@";
else if (i > 2 * n - 1 && i < 3 * n) cout << "@";
else if (j < n) cout << "@";
}
cout << "\n";
}
return 0;
}