1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
namespace 연습장
{
internal class Program
{
static void Main(string[] args)
{
using var reader = new StreamReader(Console.OpenStandardInput());
using var print = new StreamWriter(Console.OpenStandardOutput());
_11866_boj boj = new _11866_boj();
boj.boj_11866();
}
}
internal class _11866_boj
{
static int[] input;
static string[] queue;
static int n;
static int rear = 0;
static int front = 0;
public void boj_11866()
{
StringBuilder sb = new StringBuilder();
sb.Append("<");
input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
queue = new string[input[0] + 1];
n = input[0];
for (int i = 1; i <= n; i++)
queue[i] = i.ToString();
rear = n;
int cnt = 0;
int left = n;
while(left >= 1)
{
string temp = dequeue();
cnt++;
if (left == 1)
{
sb.Append(temp);
break;
}
if (cnt == input[1])
{
sb.Append(temp);
if (left > 1)
sb.Append(", ");
cnt = 0;
left--;
continue;
}
enqueue(temp);
}
sb.Append(">");
if (sb[sb.Length - 1] == '\n')
sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
public bool isQueueFull()
{
bool res = false;
if (rear % (n + 1) == front)
res = true;
return res;
}
public bool isQueueEmpty()
{
bool res = false;
if (rear == front)
res = true;
return res;
}
public void enqueue(string data)
{
if (isQueueFull())
return;
rear = (rear + 1) % (n + 1);
queue[rear] = data;
}
public string dequeue()
{
if (isQueueEmpty())
return null;
front = (front + 1) % (n + 1);
string data = queue[front];
queue[front] = null;
return data;
}
}
}
|
cs |
제거 간격이 1인 경우 마지막 문자가 2번 출력되는 오류가 있었다.
그래서 그냥 마지막 문자를 넣으면 반복문에서 나가는 방향으로 고쳐줬다.
'하루 한 접시' 카테고리의 다른 글
[백준] 2493번 : 탑 [C#] (0) | 2024.05.20 |
---|---|
[백준] 1874번 : 스택 수열 [C#] (0) | 2024.05.16 |
[백준] 2164번: 카드2 [C#] (0) | 2024.05.14 |
[백준] 1759번: 암호 만들기 [C#] (0) | 2024.05.13 |
[백준] 10828번: 스택 [C#] (0) | 2024.05.12 |