[ACM]Q102: Ecological Bin Packing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q102
{
class Program
{
static private uint[] BGC = new uint[9];
static private uint _sum = 0; static private uint _temp = 0;
static private int[] tmp = new int[3]; static private char[] par = { ' ' };
static void Main(string[] args)
{
for (; ; )
{
_temp = _sum = 0;
label: Console.Write("請輸入9個整數(以空白隔開) >>>");
try
{
BGC = Array.ConvertAll<string, uint>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), uint.Parse);
}
catch
{
goto label;
}
if (BGC.Length != 9) goto label;
for (int i = 0; i < 3; i++)
for (int j = 3; j < 6; j++)
for (int k = 6; k < 9; k++)
{
_temp = _sum;
if (i + j + k == 12)
{
_sum = BGC[i] + BGC[j] + BGC[k];
if (_temp > _sum) { _sum = _temp; }
else if (_temp == _sum)
{
if (i == 0)
{
if (tmp[0] == i && tmp[1] == 5) { }
else { tmp[0] = i; tmp[1] = j; tmp[2] = k; }
}
else if (i == 1)
{
if (tmp[0] == i && j == 3) { tmp[0] = i; tmp[1] = j; tmp[2] = k; }
}
else if (i == 2)
{
if (tmp[0] == 0 || (tmp[0] == 2 && tmp[1] == 5)) { }
else { tmp[0] = i; tmp[1] = j; tmp[2] = k; }
}
}
else { tmp[0] = i; tmp[1] = j; tmp[2] = k; }
}
}
_temp = _sum;
_sum = 0;
foreach (uint obj in BGC) _sum += obj;
for (int i = 0; i < 3; i++)
{
if (tmp[i] % 3 == 0) Console.Write("B");
else if (tmp[i] % 3 == 1) Console.Write("G");
else Console.Write("C");
}
Console.WriteLine(" {0}", _sum - _temp);
}
}
}
}