๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“• STUDY/Algorithm

[C / C++] ๋ฐฑ์ค€ 2446๋ฒˆ - ๋ณ„์ฐ๊ธฐ_9

โœ… ๋ฐฑ์ค€2446๋ฒˆ - ๋ชจ๋ž˜์‹œ๊ณ„ ๋ณ„ ์ฐ๊ธฐ

โœ… ๋ฌธ์ œ ์„ค๋ช…

์ˆซ์ž N์„ ์ž…๋ ฅํ•˜๋ฉด ์ฒซ์งธ ์ค„ 2 X N – 1๋ถ€ํ„ฐ ๋ชจ๋ž˜์‹œ๊ณ„ ๋ชจ์–‘์œผ๋กœ ๋ณ„์„ ์ฐ์œผ๋ฉด ๋œ๋‹ค.


โœ… ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์„ค๋ช…

1. 1 ~ N-1๋ฒˆ์ค„๊นŒ์ง€ ์ง๊ฐ ์‚ผ๊ฐํ˜• ๋ชจ์–‘์˜ ํˆฌ๋ช… ์‚ผ๊ฐํ˜• ์ถœ๋ ฅ

2. ์ง๊ฐ ์—ญ์‚ผ๊ฐํ˜• ๋ชจ์–‘์˜ ๋ณ„ ์‚ผ๊ฐํ˜• ์ถœ๋ ฅ (1๋ฒˆ์˜ ํˆฌ๋ช… ์‚ผ๊ฐํ˜• ๋•Œ๋ฌธ์— ๋ชจ๋ž˜์‹œ๊ณ„์ฒ˜๋Ÿผ ๋ณด์ž„)

3. N ~ 2N-1๋ฒˆ์ค„๊นŒ์ง€ ์ง๊ฐ ์—ญ์‚ผ๊ฐํ˜• ๋ชจ์–‘์˜ ํˆฌ๋ช… ์‚ผ๊ฐํ˜• ์ถœ๋ ฅ

4. ์ง๊ฐ ์‚ผ๊ฐํ˜• ๋ชจ์–‘์˜ ๋ณ„ ์‚ผ๊ฐํ˜• ์ถœ๋ ฅ (3๋ฒˆ์˜ ํˆฌ๋ช… ์‚ผ๊ฐํ˜• ๋•Œ๋ฌธ์— ๋ชจ๋ž˜์‹œ๊ณ„์ฒ˜๋Ÿผ ๋ณด์ž„)


โœ… ์ฝ”๋“œ

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);

	int i, j;
	for (i = 0; i < n - 1; i++) {
		for (j = 0; j < i; j++) // ํˆฌ๋ช… ์ง๊ฐ ์‚ผ๊ฐํ˜• ์ถœ๋ ฅ
			printf(" ");
		for (j = 0; j < (2 * n - 1) - (i * 2); j++) // ๋ณ„ ์ง๊ฐ ์—ญ์‚ผ๊ฐํ˜• ์ถœ๋ ฅ
			printf("*");
		printf("\n");
	}

	
	for (i = 0; i < n; i++) {
		for (j = 0; j < n - i - 1; j++) // ํˆฌ๋ช… ์ง๊ฐ ์—ญ์‚ผ๊ฐํ˜• ์ถœ๋ ฅ
			printf(" ");
		for (j = 0; j < i * 2 + 1; j++) // ๋ณ„ ์ง๊ฐ ์‚ผ๊ฐํ˜• ์ถœ๋ ฅ
			printf("*");
		printf("\n");
	}
	
	return 0;
}

https://github.com/2hyunjinn/Baekjoon/blob/47edcc3ebe7db69f35f3e67072d326f9d2447b2d/Baekjoon_2446.cpp 

 

GitHub - 2hyunjinn/Baekjoon

Contribute to 2hyunjinn/Baekjoon development by creating an account on GitHub.

github.com