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

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

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

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

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

0. ๊ฐœ์š”

๋ธŒ๋ก ์ฆˆ ๋ ˆ๋ฒจ์˜ ๋ณ„์ฐ๊ธฐ ๋ฌธ์ œ๋“ค์€ ํŒจํ„ด์ด ์ „๋ถ€ ๋น„์Šทํ•˜๋‹ค. ๋ฐฑ์ค€ ๊ฒ€์ƒ‰์ฐฝ์— '๋ณ„'์„ ์ž…๋ ฅํ•˜๋ฉด ๋ณ„์ฐ๊ธฐ ๋ฌธ์ œ๋“ค์ด ์—ฌ๋Ÿฌ๊ฐœ ๋‚˜์˜ค๋‹ˆ, ๋‚  ์žก๊ณ  ํ•œ๋ฒˆ ํ’€์–ด๋ณด์ž. ๋ฌผ๋ก , ๋ธŒ๋ก ์ฆˆ ๋„ˆ๋จธ์˜ ๋ฌธ์ œ๋“ค์€ ์กฐ๊ธˆ ๋” ์–ด๋ ต๋‹ค.

1. ๋ฌธ์ œ

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

 

2445๋ฒˆ: ๋ณ„ ์ฐ๊ธฐ - 8

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

www.acmicpc.net

[๋ฌธ์ œ]

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

[์ž…๋ ฅ]

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

[์ถœ๋ ฅ]

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

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

5

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

*        *
**      **
***    ***
****  ****
**********
****  ****
***    ***
**      **
*        *

2. ํ’€์ด

์ผ๋ฐ˜์ ์ธ ๋ณ„์ฐ๊ธฐ ๋ฌธ์ œ๋“ค์€ ์œ—์ค„, ๊ฐ€์šด๋ฐ์ค„, ์•„๋žซ์ค„์„ ๋‚˜๋ˆ  ์ƒ๊ฐํ•ด์•ผ ํ•œ๋‹ค.

์ด ๋ฌธ์ œ ์—ญ์‹œ ๊ทธ๋Ÿฌํ•œ๋ฐ, ์œ—์ค„(๊ฐ€์šด๋ฐ์ค„)๊ณผ ์•„๋žซ์ค„์„ ๊ตฌ๋ถ„ํ•˜์—ฌ ๋”ฐ๋กœ ์ฝ”๋”ฉํ•œ ๋‹ค์Œ ํ•˜๋‚˜๋กœ ํ•ฉ์ณ์•ผ ํ•œ๋‹ค.

์ด๋•Œ, ์œ—์ค„๊ณผ ์•„๋žซ์ค„์ด ๋Œ€์นญ ํ˜•ํƒœ์ผ ๊ฒฝ์šฐ, ๊ฐ€์žฅ ๋ฐ”๊นฅ์ชฝ for๋ฌธ์˜ ๋ฐ˜๋ณต๋ณ€์ˆ˜๋งŒ ์‚ด์ง ์†๋ด์ฃผ๋ฉด(8ํ–‰๊ณผ 28ํ–‰), for๋ฌธ ๋‚ด๋ถ€์˜ ์ฝ”๋“œ๋ฅผ ๋”ฐ๋กœ ๊ณ ์น  ํ•„์š” ์—†์ด ๋ณต์‚ฌ ๋ถ™์—ฌ๋„ฃ๊ธฐ๋กœ ํ•ด๊ฒฐ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. (์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด, 9ํ–‰~24ํ–‰ ๊นŒ์ง€์˜ ์ฝ”๋“œ์™€ 29ํ–‰~44ํ–‰ ๊นŒ์ง€์˜ ์ฝ”๋“œ๊ฐ€ ์„œ๋กœ ๋™์ผํ•˜๋‹ค.)

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 <= i; j++)
			printf("*");

		/* ๊ณต๋ฐฑ ์ฐ๊ธฐ */
		for (int j = 1; j <= 2 * (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 <= i; j++)
			printf("*");

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

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

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

	}

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