某一论坛有一个问 题:
解决此问题使用C#的&方法即可。如这题4+16+32=52:
List<int> Basic = new List<int>();
Basic.Add(2);
Basic.Add(4);
Basic.Add (8);
Basic.Add (16);
Basic.Add (32);
Basic.Add (64);
//...
int sum = 52;
//2+4+8+16=30
//32+8=40
//4+16+32=52
string s = string.Empty;
Basic.ForEach(delegate(int i)
{
if (i== (sum & i))
s = s+ "+" + i.ToString();
});
if (s.Length > 0)
s= s.Substring(1);
objInsusJsUtility.JsAlert(s + "=" + sum.ToString ());
Basic.Add(2);
Basic.Add(4);
Basic.Add (8);
Basic.Add (16);
Basic.Add (32);
Basic.Add (64);
//...
int sum = 52;
//2+4+8+16=30
//32+8=40
//4+16+32=52
string s = string.Empty;
Basic.ForEach(delegate(int i)
{
if (i== (sum & i))
s = s+ "+" + i.ToString();
});
if (s.Length > 0)
s= s.Substring(1);
objInsusJsUtility.JsAlert(s + "=" + sum.ToString ());
执行结果: