-
Notifications
You must be signed in to change notification settings - Fork 0
/
Metodi.cs
68 lines (60 loc) · 2.26 KB
/
Metodi.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Logistica
{
internal class Metodi
{
private static int Min(int int1, int int2)
{
if (int1 > int2)
return int2;
else
return int1;
}
private static String FormatString(int n_produttore, int n_consumatore, int prodotti, int prezzo_unit)
{
return "Da Produttore " + (n_produttore + 1) + " a Consumatore " + (n_consumatore + 1) + " : " + prodotti + " unità a " +
prezzo_unit + " € = " + prodotti * prezzo_unit + " €\n";
}
private static String FinalFormatString(int tot)
{
return "Totale costi = " + tot + " €";
}
public static String NordOvest(int[][] tabella)
{
int inner_len = tabella[0].Length;
String s = "";
bool done = false;
int current_prod = 0;
int current_consum = 0;
int tot = 0;
while (!done)
{
if (tabella[tabella.Length - 1][current_prod] > 0)
if (tabella[current_consum][inner_len-1] > 0)
{
int prodotti = Min(tabella[tabella.Length - 1][current_prod], tabella[current_consum][inner_len-1]);
tabella[tabella.Length - 1][current_prod] -= prodotti;
tabella[current_consum][inner_len-1] -= prodotti;
tot += tabella[current_consum][current_prod] * prodotti;
s += FormatString(current_consum, current_prod, prodotti, tabella[current_consum][current_prod]);
}
else
if (current_consum < tabella.Length)
current_consum += 1;
else
done = true;
else
if (current_prod < tabella[tabella.Length - 1].Length - 1)
current_prod += 1;
else
done = true;
}
return s + FinalFormatString(tot);
}
}
}