def input;
def diff , rem;
def extra ,each
def t,k;
def t1;
int j;
result_final = new SimpleResults();
def a =[0,0,0,0]
def ind =[0,0,0,0]
int i=0;
while(res_set.next()) // for converting result set into array list
{ if(i>=0 && i<4)
{ ind[i] = res_set.getValue("col1");
a[i] = res_set.getValue("col2");
++i;
}
else
{
input= res_set.getValue("col2");
}
}
for(i=0; i<4; i++)
{
for(j=1; j<(4-i); j++)
{
if(a[j-1]>a[j])
{
t = a[j-1];
t1 = ind[j-1];
a[j-1]=a[j];
ind[j-1]=ind[j];
a[j]=t;
ind[j]=t1;
}
}
}
i=0;
diff =a[3]-a[0];
if (diff <= input)
{
a[0]=a[0]+ diff;
rem = input-diff;
for(j = 0;j < 4;j++)
{
if((j!= 0)&&(j!= 3)&&(rem > 0))
{
diff = a[3]-a[j];
if(diff <= rem)
{
a[j]+=diff;
rem = rem-diff;
}
else
{ a[j]+=rem;
rem=0;
}
}
}
}
else
{
a[0]+=input;
}
if (rem > 0) // for allocating remaining value
{
if (rem == 1)
{
a[0] += 1;
}
else if (rem == 2)
{
a[0] += 1;
a[1] += 1;
}
else if (rem == 3)
{
a[0] += 1;
a[1] += 1;
a[2] += 1;
}
else if (rem >= 4)
{
extra = rem%4 ;
rem=rem-extra;
each =rem/4;
for(k = 0;k<4;k++)
{
a[k] +=each;
}
if (extra > 0) // for allocating remaining value
{
if (extra == 1)
{
a[0] += 1;
}
else if (extra == 2)
{
a[0] += 1;
a[1] += 1;
}
else if (extra == 3)
{
a[0] += 1;
a[1] += 1;
a[2] += 1;
}
}
}
}
//its working properly but not following the second criteria
Edited by WingedPanther, 06 September 2011 - 04:34 AM.


Sign In
Create Account

Back to top









