庞果网英雄会试题2大数相乘c#写法
写了半天要提交,发现要求java写郁闷...发到这边来看看吧.
class Program
{
/// <summary>
/// 两个大数相乘:char* multiply(char*,char*)。给了两个字符串,
/// 每个都是代表了一个很长的10进制表示的数, 比如 String str1 = "23456789009877666555544444";
/// String str2 = "346587436598437594375943875943875", 最后求出它们的乘积。 不用jdk的数学运算包BigInteger.或者类似的包。
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
string s1 = "23456789009877666555544444";
string s2 = "346587436598437594375943875943875";
string res = LargeNumber(s1, s2);
}
static string LargeNumber(string s1, string s2)
{
string result = "";
int s1Length = s1.Length;
List<MutiValue> mutiList = new List<MutiValue>();
for (int i = 0; i <= s1Length - 1; i++)
{
int currenti = Convert.ToInt32(s1[i] + "");
List<MutiValue> tempMuti = SingleNumberMultiply(currenti, s2, s1Length - 1 - i);
mutiList.AddRange(tempMuti);
}
result = getResult(mutiList);
return result;
}
static List<MutiValue> SingleNumberMultiply(int i1, string s2, int i1position)
{
List<MutiValue> mutiList = new List<MutiValue>();
int i2length = s2.Length;
for (int i = 0; i <= i2length - 1; i++)
{