using System;
using System.Collections;
namespace Beep
{
public class Class3
{
static void Main(string[] args)
{
app my=new app(8000,100);
my.work();
string s=my.GetExpress();
Console.WriteLine(s);
my=new app(6000,100);
my.work();
s=my.GetExpress();
Console.WriteLine(s);
Console.ReadLine();
}
}
public class app
{
int[] intArr = new int[] {1132,544,844,929,348,1136,1066,1197};//全局变量
int boss ;
public ArrayList list = new ArrayList();//全局变量
private int mod;
private int imulti;
private int end;
private int distance;
private ArrayList alint=new ArrayList();
private Hashtable hash=new Hashtable();
public app()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public app(int iboss,int iend)
{
for(int i=0;i<intArr.Length;i++)
{
alint.Add(intArr[i]);
}
alint.Sort();
this.boss=iboss;
this.end=iend;
}
public bool work()
{
int boss=this.boss;
for(int i=this.alint.Count-1;i>=0;i--)
{
if(boss<(int)this.alint[i])
continue;
this.mod=boss%(int)this.alint[i];
this.imulti=(boss-this.mod)/(int)this.alint[i];
if(this.mod>this.end||this.mod>=0)
{
hash.Add((int)this.alint[i],this.imulti);
boss=this.mod;
}
else
{
break;
}
}
foreach(int s in hash.Keys)
{
Console.WriteLine("hash[{0}]={1}",s,hash[s]);
}
this.distance=this.GetDistance();
if(this.distance<this.end)
return true;
return false;
}
private int GetDistance()
{
int subsum=0;
foreach(int i in this.hash.Keys)
{
subsum+=(int)this.hash[i]*i;
}
return this.boss-subsum;
}
public string GetExpress()
{
string subexp="";
foreach(int i in this.hash.Keys)
{
subexp+="+"+i.ToString()+"*"+this.hash[i].ToString();
}
return this.boss.ToString()+"-("+subexp.Substring(1)+")="+this.distance.ToString();
}
}
}