728x90
https://www.acmicpc.net/problem/2741
2741번: N 찍기
자연수 N이 주어졌을 때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.
www.acmicpc.net
https://docs.microsoft.com/ko-kr/dotnet/api/system.text.stringbuilder.appendline?view=netcore-3.1
StringBuilder.AppendLine 메서드 (System.Text)
이 인스턴스의 끝에 기본 줄 종결자 또는 지정한 문자열의 복사본과 기본 줄 종결자를 추가합니다.Appends the default line terminator, or a copy of a specified string and the default line terminator, to the end of this inst
docs.microsoft.com
using System;
using System.Text;
namespace backjoon
{
class Program
{
static void Main(string[] args)
{
int t = int.Parse(Console.ReadLine());
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= t; i++)
{
sb.AppendLine(i.ToString());
}
Console.WriteLine(sb.ToString());
}
}
}
sb.AppendLine(i.Tostring()); 대신에 sb.Append(i + "\n"); 써도 됌
728x90
'게임 프로그래밍 > C#' 카테고리의 다른 글
[백준]C# 코딩 : 11021번(A + B - 7) (0) | 2021.08.25 |
---|---|
[백준]C# 코딩 : 2742번(기찍 N) (0) | 2021.08.24 |
[백준]C# 코딩 : 15552번(빠른 A + B) (0) | 2021.08.24 |
[백준]C# 코딩 : 8393번(합) (0) | 2021.08.24 |
[백준]C# 코딩 : 10950번(A + B - 3) (0) | 2021.08.22 |