알고리즘 문제 풀이/백준
[백준 2439번/C#] 별 찍기 - 2
Ardmos :)
2023. 10. 21. 15:34
배운 점:
실수한 점:
using System;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
int lineCount = int.Parse(Console.ReadLine());
string answer;
for (int i = 1; i <= lineCount; i++) {
// 매 줄 초기화
answer = "";
// 최대공백(lineCount) - 현재 줄에 찍힐 별 개수(i) = 실제 공백(k)
for (int k = 0; k < lineCount-i; k++)
{
answer += " ";
}
// 별 개수(i) 만큼 별 찍기
for (int j = 1; j <= i; j++)
{
answer += "*";
}
Console.WriteLine(answer);
}
}
}
}
728x90