using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
class MainClass
{
public class Banker
{
static int[] available = new int[4]; //
static int[,] max = new int[5, 4]; //
static int[,] allocation = new int[5, 4]; //
static int[,] need = new int[5, 4]; //
static int[] request = new int[4]; //
int thread; //
//
public void getData()
{
Console.Write("A,B,C,D:");
//A,B,C
for (int i = 0; i 4)
{
Console.WriteLine(",");
getThread();
}
else
{
this.thread = thread;
Console.WriteLine("(0-4)");
for (int i = 0; i need[thread, 0] || request[1] > need[thread, 1] || request[2] > need[thread, 2] || request[3] > need[thread, 3])
{
Console.WriteLine(thread + ",");
getThread();
}
else
{
if (request[0] > available[0] || request[1] > available[1] || request[2] > available[2] || request[3] > available[3])
{
Console.WriteLine(thread + ",");
getThread();
}
}
changeData(thread);
if (check(thread))
{
getThread();
}
else
{
recoverData(thread);
getThread();
}
}
}
//thread,
public void changeData(int thread)
{
for (int i = 0; i work[i])
{
//(need[j,i]+"*"+i+work[i]);
j++;
break;
}
else if (i == 2)
{
for (int m = 0; m < 4; m++)
{
work[m] += allocation[j, m];
}
finish[j] = true;
queue[k] = j;
k++;
j = 0; //
}
}
}
//
for (int p = 0; p < 5; p++)
{
if (finish[p] == false)
{
Console.WriteLine(",");
return false;
}
}
Console.WriteLine(",:");
for (int q = 0; q < 5; q++)
{
Console.WriteLine(queue[q]);
}
return true;
}
//needavailable
public void showData()
{
Console.WriteLine("need");
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
Console.WriteLine(need[i, j] + " ");
}
}
Console.WriteLine("available");
for (int j = 0; j < 4; j++)
{
Console.WriteLine(available[j] + " ");
}
}
static void Main(string[] args)
{
Banker bk = new Banker();
bk.getData();
bk.getThread();
}
}
}
}