반응형
String Builder 알아보러가기
C# - StringBuilder
String String 개체는 변경할 수 없다. System.String 클래스에서 메서드 중 하나를 사용할 때마다 메모리에 새 문자열 개체가 생성되므로, 새 개체에 대한 공간을 새로 할당 되어진다. 그러므로 문자열
code-piggy.tistory.com
List 메소드 알아보러가기
C# - List (찾기, 추가, 제거, 정렬 메서드)
List를 사용하기 위해서는 System.Collections.Generic 네임스페이스를 추가해줘야한다. using System.Collections.Generic; List pig = new List(); 1. Add List 끝 부분에 추가 public void Add (T item); List pig = new List(); pig.Add(2);
code-piggy.tistory.com
using System;
using System.Collections.Generic;
using System.Text;
namespace baek2
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
int N = int.Parse(input);
List<string> list = new List<string>();
int count = N-1;
for(int i = 0; i< N; i++)
{
StringBuilder myStringBuilder = new StringBuilder();
for (int k =0; k<count; k++)
{
myStringBuilder.Append(" ");
}
for (int j = 0; j < (i*2)+1; j++)
{
myStringBuilder.Append("*");
}
list.Add(myStringBuilder.ToString());
count--;
}
foreach(var i in list)
{
Console.WriteLine(i);
}
list.Reverse();
for(int i = 1; i<list.Count; i++)
{
Console.WriteLine(list[i]);
}
}
}
}
반응형
'코딩테스트 준비 > 백준 C#' 카테고리의 다른 글
백준 C# 10988 (0) | 2023.05.08 |
---|---|
백준 C# 10812 +) 풀이 (0) | 2023.05.03 |
백준 C# 3003 (0) | 2023.04.27 |
백준 C# 25083 (0) | 2023.04.27 |
백준 C# 11718 (0) | 2023.04.26 |
댓글