하루 한 접시
[백준] 8979번: 올림픽 [C#]
NaZZU
2024. 5. 8. 00:53
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
|
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
namespace 연습장
{
internal class Program
{
static StringBuilder sb = new StringBuilder();
static void Main(string[] args)
{
using var reader = new StreamReader(Console.OpenStandardInput());
using var print = new StreamWriter(Console.OpenStandardOutput());
_8979_boj boj = new _8979_boj();
boj.boj_8979();
}
}
internal class _8979_boj
{
public void boj_8979()
{
int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int cnt = input[0];
int obj = input[1];
int[][] countries = new int[cnt][];
for (int i = 0; i < cnt; i++)
{
countries[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
}
int[] temp;
for (int i = 0; i < cnt; i++)
{
for (int j = i + 1; j < cnt; j++)
{
for (int k = 1; k < 4; k++)
{
if (countries[i][k] == countries[j][k])
{
if (k == 4)
{
temp = countries[i + 1];
countries[i + 1] = countries[j];
countries[j] = temp;
break;
}
continue;
}
if (countries[i][k] < countries[j][k])
{
temp = countries[i];
countries[i] = countries[j];
countries[j] = temp;
break;
}
if (countries[i][k] > countries[j][k])
break;
}
}
}
int strick = 1;
for (int i = 1; i <= cnt; i++)
{
if (countries[i - 1][0] == obj)
{
if (i > 2 && countries[i - 2][1] == countries[i - 1][1] && countries[i - 2][2] == countries[i - 1][2] && countries[i - 2][3] == countries[i - 1][3])
{
for (int j = i - 2; j >= 0; j--)
{
if (countries[i - 1][1] != countries[j][1] || countries[i - 1][2] != countries[j][2] || countries[i - 1][3] != countries[j][3])
{
Console.WriteLine(j + 2);
return;
}
}
}
Console.WriteLine(i);
return;
}
}
}
}
}
|
cs |
코드를 더 이쁘게 짜는 방법이 있을텐데.... 너무 안예쁜 코드다...