Hi!
I submitt my answer for BISHOP problem and always have Runtime error. Can your check my problem (at my local C# VS2008 all works fine. I lock MSDN and not found any methods whitch not exists in .Net FW 1.0). Thanks with advansed.
using System;
class Program
{
class BigInt
{
const int DEC_BASE = 5;
decimal[] data;
int sign = 1;
public BigInt()
{
}
public BigInt(BigInt a)
{
data = new decimal[a.data.Length];
a.data.CopyTo(data, 0);
sign = a.sign;
}
public static BigInt Parse(string s)
{
BigInt val = new BigInt();
if (s[0] == '-')
{
val.sign = -1;
s = s.Substring(1, s.Length - 1);
}
int i = s.Length / (1 + DEC_BASE) + 1;
s = s.PadLeft(i * DEC_BASE, '0');
val.data = new decimal[i];
while (i-- > 0)
{
string n = s.Substring(i * DEC_BASE, DEC_BASE);
val.data[i] = decimal.Parse(n);
}
return val;
}
public string AsString()
{
int i = data.Length;
string o = string.Empty;
while (i-- > 0)
{
o = string.Format("{0:F00}", (i == 0 ? sign : 1) * data[i]).PadLeft(DEC_BASE, i == 0 ? ' ' : '0').Trim() + o;
}
return o;
}
public static BigInt operator -(BigInt a, int b)
{
return a + (-b);
}
public static BigInt operator +(BigInt a, int b)
{
BigInt val = new BigInt(a);
int i = val.data.Length;
val.data[--i] += b * val.sign;
val.Update();
return val;
}
public static BigInt operator *(BigInt a, int b)
{
BigInt val = new BigInt(a);
int i = val.data.Length;
while (i-- > 0)
{
val.data[i] *= b;
}
val.Update();
return val;
}
public static BigInt operator +(BigInt a, BigInt b)
{
return a;
}
private void Update()
{
int i = data.Length;
decimal carry = 0;
while (i-- > 0)
{
data[i] += carry;
carry = 0;
if (data[i] > (decimal)(Math.Pow(10, DEC_BASE)) - 1)
{
carry = data[i] / (decimal)Math.Pow(10, DEC_BASE);
data[i] -= carry * (decimal)Math.Pow(10, DEC_BASE);
}
else if (data[i] < 0)
{
if (i > 0) carry = -1;
else
{
sign = -sign; data[0] = -data[0];
}
data[i] -= carry * (decimal)Math.Pow(10, DEC_BASE);
}
}
if (carry > 0)
{
decimal[] val = new decimal[data.Length + 1];
data.CopyTo(val, 1);
sign = 1;
val[0] = carry;
data = val;
}
if (carry < 0)
{
sign = -sign;
}
for (i = 0; i < data.Length; i++)
{
if (data[i] != 0) break;
}
if (i > 0 & data.Length > 1)
{
int size = data.Length - i;
decimal[] val = new decimal[size];
while (i > 0)
{
val[size - i] = data[data.Length - i];
i--;
}
data = val;
}
}
}
static void Main()
{
while (0 == 0)
{
BigInt val = BigInt.Parse(Console.ReadLine());
Console.WriteLine((val * 2 - 2).AsString());
}
}
}