반응형
SMALL
문제
문제풀이
using System;
using System.Collections.Generic;
using System.IO;
namespace BOJ
{
internal class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader(Console.OpenStandardInput());
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
int[] NK = Array.ConvertAll(sr.ReadLine().Split(), int.Parse);
int N = NK[0];
int K = NK[1];
Queue<int> q = new Queue<int>();
for (int i = 1; i <= N; i++) { q.Enqueue(i); }
if(q.Count == 1) { sw.WriteLine("<{0}>", q.Peek()); }
else
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < K - 1; j++)
{
q.Enqueue(q.Dequeue());
}
if (i == 0) { sw.Write("<{0}, ", q.Peek()); }
else if (i == N - 1) { sw.Write("{0}>", q.Peek()); }
else { sw.Write("{0}, ", q.Peek()); }
q.Dequeue();
}
}
sr.Close();
sw.Close();
}
}
}
결과창
q에 1만 들어갈 경우를 고려 못해 세번 틀렸다....
항상 예외처리를 확인하고 제출하는 버릇을 가져야겠다.
반응형
LIST
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ] 1940번 주몽 C# 사용 풀이 (두포인터 알고리즘 ) (0) | 2023.02.20 |
---|---|
[BOJ] 2003번 수들의 합 2 C#사용 풀이 (0) | 2023.02.17 |
[BOJ] 7785번 회사에 있는 사람 - 미해결 (0) | 2023.02.12 |
[BOJ] 오등큰수 C# 사용 풀이 (복습 대상) (0) | 2023.02.10 |
[BOJ] 약수 2501번 C# 사용 풀이 (0) | 2023.02.09 |