๐•ƒ๐•ฆ๐•„๐•š๐•ฃ

ใ€ŒโŒจ๏ธแด„sใ€PS/๋ฐฑ์ค€_์ˆ˜ํ•™&๊ตฌํ˜„

[Baekjoon/๋ฐฑ์ค€][2522][C/C++] ๋ณ„ ์ฐ๊ธฐ - 12

by ๋ฃจ๋ฐ€๐•ƒ๐•ฆ๐•„๐•š๐•ฃ2023. 1. 19.
728x90
๋ฐ˜์‘ํ˜•
ใ€Ž๋ชฉ์ฐจใ€
0. ๊ฐœ์š”

1. ๋ฌธ์ œ
2. ํ’€์ด
3. ์ฝ”๋“œ

0. ๊ฐœ์š”

๋‹ค์‹œ ๋Œ์•„์˜จ ๋ณ„์ฐ๊ธฐ ์‹œ๊ฐ„. ์–ด๋ ต์ง€ ์•Š์€ ๋ฌธ์ œ๋ผ ๋ฐ”๋กœ ํ’€์ด๋กœ ๋„˜์–ด๊ฐ€๊ฒ ๋‹ค.

๋งŒ์•ฝ ๋ฌธ์ œ์— ๋Œ€ํ•œ ์„ค๋ช…์ด ๋ถ€์กฑํ•˜๋‹ค ๋Š๊ปด์ง„๋‹ค๋ฉด, ์•ž์„œ ์˜ฌ๋ ค๋‘” ๋ณ„์ฐ๊ธฐ ํฌ์ŠคํŒ…๋“ค์„ ์ฐธ์กฐํ•˜์ž.

1. ๋ฌธ์ œ

https://www.acmicpc.net/problem/2522

 

2522๋ฒˆ: ๋ณ„ ์ฐ๊ธฐ - 12

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ 2×N-1๋ฒˆ์งธ ์ค„๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ ๋ณ„์„ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net

[๋ฌธ์ œ]

์˜ˆ์ œ๋ฅผ ๋ณด๊ณ  ๊ทœ์น™์„ ์œ ์ถ”ํ•œ ๋’ค์— ๋ณ„์„ ์ฐ์–ด ๋ณด์„ธ์š”.

[์ž…๋ ฅ]

์ฒซ์งธ ์ค„์— N(1 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค.

[์ถœ๋ ฅ]

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ 2×N-1๋ฒˆ์งธ ์ค„๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ ๋ณ„์„ ์ถœ๋ ฅํ•œ๋‹ค.

[์˜ˆ์ œ ์ž…๋ ฅ 1]

3

[์˜ˆ์ œ ์ถœ๋ ฅ 1]

  *
 **
***
 **
  *

2. ํ’€์ด

'์œ„์ชฝใ†๊ฐ€์šด๋ฐ' ํŒจํ„ด๊ณผ '์•„๋ž˜์ชฝ' ํŒจํ„ด์„ ๋‚˜๋ˆ ์„œ ์ƒ๊ฐํ•˜์ž.

๊ณต๋ฐฑ์€ 'N-1, N-2, N-3, N-2, N-1' ์ˆœ์„œ๋Œ€๋กœ ์ฐํžˆ๊ณ , *์€ 'N-2, N-1, N, N-1, N-2' ์ˆœ์„œ๋กœ ์ฐํžŒ๋‹ค.

3. ์ฝ”๋“œ

#pragma warning (disable:4996)
#include <stdio.h>

int main(int argc, char* argv[]) {
	int N; scanf("%d", &N);

	/* ์œ„์ชฝ */
	for (int i = 1; i <= N; i++) {

		/* ๊ณต๋ฐฑ ์ฐ๊ธฐ */
		for (int j = 1; j <= N - i; j++)
			printf(" ");

		/* ๋ณ„ ์ฐ๊ธฐ */
		for (int j = 1; j <= i; j++)
			printf("*");

		/* ๊ฐœํ–‰ */
		printf("\n");
	}

	/* ์•„๋ž˜์ชฝ */
	for (int i = N-1; i >= 1; i--) {

		/* ๊ณต๋ฐฑ ์ฐ๊ธฐ */
		for (int j = 1; j <= N - i; j++)
			printf(" ");

		/* ๋ณ„ ์ฐ๊ธฐ */
		for (int j = 1; j <= i; j++)
			printf("*");

		/* ๊ฐœํ–‰ */
		printf("\n");
	}

	return 0;
}
728x90
๋ฐ˜์‘ํ˜•