-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeForcesBeautifulMatrix.cs
More file actions
121 lines (95 loc) · 3.2 KB
/
Copy pathCodeForcesBeautifulMatrix.cs
File metadata and controls
121 lines (95 loc) · 3.2 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace HackerrankSolutionList
{
class Program
{
static void Main(string[] args)
{
int[,] matrix = new int[5, 5];
int rowTarget = 2;
int columnTarget = 2;
int rows = 0;
int columns = 0;
for (int x = 0; x < 5; x++)
{
string d = Console.ReadLine();
string[] proses = d.Split(' ');
for (int c = 0; c < 5; c++)
{
if(int.Parse(proses[c]) == 1)
{
rows = x;
columns = c;
}
matrix[x, c] = int.Parse(proses[c]);
}
}
//ini metode cepat(cukup cepat wkwkw) kalau mau lebih cepat tinggal cek pas matrix = 1 copy rows sama column nya trus lakuin kauyak dibawah.
Console.WriteLine(Math.Abs(rowTarget - rows) + Math.Abs(columnTarget - columns));
//ini metode alternatif walaupun mungkin sufficient tetapi ini adlaah metode yang paling sederhana(perlu ditingkatkan sedikit lagi untuk Optimasi).
int rowChanged = 0;
int ColumnChanged = 0;
bool stop1 = false;
bool stop2 = false;
for (; ; )
{
if (stop1 == true && stop2 == true)
{
Console.WriteLine(ColumnChanged+rowChanged);
break;
return;
}
if (rows < rowTarget)
{
rows = rows + 1;
rowChanged++;
}
else
{
stop1 = true;
}
if(columns < columnTarget)
{
columns = columns + 1;
ColumnChanged++;
}
else
{
stop2 = true;
}
}
bool stopp1 = false;
bool stopp2 = false;
for (; ; )
{
if (stopp1 == true && stopp2 == true)
{
Console.WriteLine(ColumnChanged + rowChanged);
break;
return;
}
if (rows > rowTarget)
{
rows = rows - 1;
rowChanged++;
}
else{
stopp1 = true;
}
if (columns > columnTarget)
{
columns = columns - 1;
ColumnChanged++;
}
else
{
stopp2 = true;
}
}
Console.ReadLine();
}
}
}