문제 : https://www.acmicpc.net/problem/2441


[알고리즘풀이]

1 ~ N 개의 줄에 대해 i번째 줄은 (i - 1)개의 공백과 (n + 1) - i 개의 *을 출력하면 된다.

#include<iostream>

using namespace std;

int main() { 
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) { 
		for (int j = 0; j < (i - 1); j++)
			cout << ' ';
		for (int j = 0; j < (n + 1) - i; j++)
			cout << '*';
		cout << '\n';
	} 
	return 0; 
}


 

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ] 2443 - '별 찍기 - 6'  (0) 2019.10.26
[BOJ] 2442 - '별 찍기 -5'  (0) 2019.10.26
[BOJ] 2440 - '별 찍기 - 3'  (0) 2019.10.26
[BOJ] 2439 - '별 찍기 - 2'  (0) 2019.10.26
[BOJ] 2438 - '별 찍기 - 1'  (0) 2019.10.26

문제 : https://www.acmicpc.net/problem/2440


[알고리즘풀이]

1 ~ n 개의 줄에 대해 i번째 줄은 (n + 1) - i 개만큼 *을 출력하면 된다.

#include<iostream>

using namespace std;

int main() { 
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) { 
		for (int j = 0; j < (n + 1) - i; j++)
			cout << '*';
		cout << '\n';
	} 
	return 0; 
}

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ] 2442 - '별 찍기 -5'  (0) 2019.10.26
[BOJ] 2441 - '별 찍기 - 4'  (0) 2019.10.26
[BOJ] 2439 - '별 찍기 - 2'  (0) 2019.10.26
[BOJ] 2438 - '별 찍기 - 1'  (0) 2019.10.26
[BOJ] 2661 - 좋은 수열  (0) 2019.10.26

문제 : https://www.acmicpc.net/problem/2439


[알고리즘풀이]

공백과 *을 포함하면 결국 모든 n개의 줄이 n개의 공백과 *을 출력해야 된다.

이때, i번 째 줄은 (n - i)개의 공백, i 개의 *을 출력하면 된다.

#include<iostream>

using namespace std;

int main() { 
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) { 
		for (int j = 0; j < n - i; j++)
			cout << ' ';
		for (int j = 0; j < i; j++)
			cout << '*';
		cout << '\n';
	} 
	return 0; 
}


 

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ] 2441 - '별 찍기 - 4'  (0) 2019.10.26
[BOJ] 2440 - '별 찍기 - 3'  (0) 2019.10.26
[BOJ] 2438 - '별 찍기 - 1'  (0) 2019.10.26
[BOJ] 2661 - 좋은 수열  (0) 2019.10.26
[BOJ] 1600 - 말이 되고픈 원숭이  (0) 2019.10.25

문제 : https://www.acmicpc.net/problem/2438


[알고리즘풀이]

i 번째 줄은 i 개 *을 출력하면 된다.

#include<iostream>

using namespace std;

int main() { 
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) { 
		for (int j = 0; j < i; j++) {
			cout << '*';
		}
		cout << '\n';
	} 
	return 0; 
}


 

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ] 2440 - '별 찍기 - 3'  (0) 2019.10.26
[BOJ] 2439 - '별 찍기 - 2'  (0) 2019.10.26
[BOJ] 2661 - 좋은 수열  (0) 2019.10.26
[BOJ] 1600 - 말이 되고픈 원숭이  (0) 2019.10.25
[BOJ] 14331 - Lazy Spelling Bee (Large)  (0) 2019.10.15

+ Recent posts