分类: C/C++
2011-09-06 13:58:34
//tranfor the string to int array
int[] inum1 = new int[num1Length];
//先将字符串转化为整数数组(每个数字字符减去48即可)
for (int i = 0; i < num1Length; i++)
{
inum1[i] = (int)num1[i] - 48;
}
int[] inum2 = new int[num2Length];
for (int i = 0; i < num2Length; i++)
{
inum2[i] = (int)num2[i] - 48;
}
int[] result = new int[num1Length + num2Length];
for (int i = num1Length - 1; i >= 0; i--)
{
for (int j = num2Length - 1; j >= 0; j--)
{
result[i + j + 1] += inum1[i] * inum2[j];
result[i + j] += result[i + j + 1] / 10;
result[i + j + 1] %= 10;
}
}
char[] temp = new char[num1Length + num2Length];
for (int i = 0; i < (num1Length + num2Length); i++)
{
temp[i] = (char)(result[i] + 48);
}
String sResult = new String(temp);
return sResult;
}