-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExampleProgram.cs
More file actions
133 lines (120 loc) · 3.33 KB
/
ExampleProgram.cs
File metadata and controls
133 lines (120 loc) · 3.33 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
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.IO;
namespace hashcode
{
class SmallClass
{
// predetermined integers from input file
static int R = 3;
static int C = 5;
static int[,] inttop;
static bool isFirstTime = true;
static int slices = 0;
static int i = 0;
static int[,] sliceSaver = new int[7, 4];
public static void Main (string[] args)
{
int score = 0;
//Instantiate a StreamReader to read from the text file.
StreamReader sr = new StreamReader (@"example.in");
// gets the first role from input file out of the way
char[] row1 = sr.ReadLine ().ToCharArray();
// string that stores all the elements from the input file (T and M)
string toppings = sr.ReadToEnd ();
// character array
char[] chartop = toppings.ToCharArray();
// integer array that converts T to 1, M to 0
inttop = new int[R,C];
// filling inttop with values
int z=0;
for (int x=0;x<R;x++) {
for (int y=0;y<C;y++) {
if (chartop [z] == 'T') {
inttop [x, y] = 1;
} else if (chartop [z] == 'M')
inttop [x, y] = 0;
else{
y--;
}
z++;
}
}
// 3x2 slices
int slicesCut = slicer (0, 0, 2, 1, 5, 6);
slices = slicesCut + slices;
score = slicesCut * 6;
Console.WriteLine (slices + " " + score + "pts");
// 3x1 slices
slicesCut = slicer (0, 0, 2, 0, 1, 3);
slices = slicesCut + slices;
score = score + slicesCut * 3;
Console.WriteLine (slices + " " + score + "pts");
documenter();
Console.WriteLine ("DONE");
Console.ReadKey ();
}
// the method that creates the output file and writes to it
public static void documenter(){
Console.WriteLine ("Saving output file...");
for (int e=0;e<slices;e++) {
string line = sliceSaver[e,0] + " " + sliceSaver[e,1] + " " + sliceSaver[e,2] + " " + sliceSaver[e,3];
using (StreamWriter sw = new StreamWriter ("example_output.txt", true)) {
if (isFirstTime) {
sw.WriteLine (slices);
isFirstTime = false;
}
sw.WriteLine (line);
}
}
}
// the method that cuts the pizza into suitable slices
public static int slicer(int r1, int c1, int r2, int c2, int min, int max){
int sliceCell = 0;
int slice = 0;
for (int r=0;r<R-r2;r++) {
for (int c=0;c<C-c2;c++) {
for (int x=r1+r;x<=r2+r;x++) {
for (int y=c1+c;y<=c2+c;y++) {
if (inttop [x, y] == 1) {
sliceCell++;
}
}
}
if (sliceCell < max) {
if (sliceCell >= min) {
bool isSlice = checker (r1 + r, c1 + c, r2 + r, c2 + c);
if (isSlice)
slice++;
}
}
sliceCell = 0;
}
}
return slice;
}
public static void saver(int r1, int c1, int r2, int c2) {
sliceSaver[i,0] = r1;
sliceSaver[i,1] = c1;
sliceSaver[i,2] = r2;
sliceSaver[i,3] = c2;
i++;
}
public static bool checker(int r1, int c1, int r2, int c2) {
bool check = true;
for (int a = 0; a <= i; a++) {
if (a == i)
break;
for (int r = r1; r <= r2; r++) {
for (int c = c1; c <= c2; c++) {
if ((sliceSaver [a, 0] <= r && r <= sliceSaver [a, 2]) && (sliceSaver [a, 1] <= c && c <= sliceSaver [a, 3])) {
check = false;
}
}
}
}
if (check)
saver (r1, c1, r2, c2);
return check;
}
}
}