大数相乘 痛定思痛。 2024-02-18 20:43 11阅读 0赞 package com.test; public class Multiply \{ public static void multiply(char a\[\], char b\[\]) \{ int alen=a.length; int blen=b.length; int\[\] result = new int\[alen + blen\]; for (int i = 0; i < alen + blen; i++) result\[i\] = 0; int resultCount=blen+alen-2; // 对齐逐位相乘 for (int j = blen-1; j >= 0; j--) \{ int tempb=(int)(b\[j\]-'0'); for (int i =alen - 1; i >= 0; i--) \{ int tempa=(int)(a\[i\]-'0'); result\[i + j + 1\] += tempa \* tempb; int carry = result\[i+j+1\] / 10; result\[i+j+1\] = result\[i+j+1\] % 10; if (carry > 0) \{ result\[i+j\] += carry; \} \} \} if(result\[0\]>0) \{ resultCount+=1; \} System.out.print("乘积:"); for (int j=0;j <=resultCount; j++) \{ System.out.print(result\[j\]); \} \} public static void main(String\[\] args) \{ //String str1 = "999"; //String str2 = "999"; String str1 = "23456789009877666555544444"; String str2 = "34658743659843759437594387594387"; char\[\] s1 = str1.toCharArray(); char\[\] s2 = str2.toCharArray(); System.out.println("乘数1:"+str1); System.out.println("乘数2:"+str2); multiply(s1, s2); \} \}
相关 大数相乘 void mul(string a, string b) { int max = 0; int c[1000] = {0}; in r囧r小猫/ 2022年12月04日 08:47/ 0 赞/ 59 阅读
相关 大数相乘 一、背景 最近在看算法的时候发现了一个问题,我们都知道方法的形参是要指定类型的,假如有以下方法 public int example(int a,int b){ 傷城~/ 2022年09月30日 13:55/ 0 赞/ 250 阅读
相关 大数相乘 参考地址:[http://www.cnblogs.com/heyonggang/p/3599857.html][http_www.cnblogs.com_heyonggang_ 悠悠/ 2022年08月20日 06:29/ 0 赞/ 230 阅读
相关 大数相乘 [用分治法实现大数乘法,加法,减法(java实现)][java] 大数乘法即多项式乘法问题,求A(x)与B(x)的乘积C(x),朴素解法的复杂度O 小咪咪/ 2022年08月19日 15:12/ 0 赞/ 223 阅读
相关 大数相乘 无意中看到一个华为面试题,使用代码计算[1234567891011121314151617181920\2019181716151413121110987654321][123 系统管理员/ 2022年08月11日 20:29/ 0 赞/ 231 阅读
相关 大数相乘 题目:请使用代码计算1234567891011121314151617181920\2019181716151413121110987654321。 答: ![复制代码][ Bertha 。/ 2022年08月05日 08:54/ 0 赞/ 241 阅读
相关 大数相乘 在这之前我们先来了解一下Java 中每种基本数据类型所占存储空间的大小。其中 1Byte = 8bit。 <table> <tbody> <tr> <th> 朱雀/ 2022年06月02日 02:36/ 0 赞/ 298 阅读
相关 大数相乘 设X和Y是n位的二进制整数,现在要计算X\Y的结果 将a和b分为两段,每段长均为总长的1/2, ![20180329214901958][] 拼搏现实的明天。/ 2022年05月28日 05:06/ 0 赞/ 249 阅读
相关 大数相乘 题目 编写两个任意位数的大数相乘的程序,给出计算结果。比如: > 题目描述: 输出两个不超过100位的大整数的乘积。 > 输入: 输入两个大整数,如1234567 今天药忘吃喽~/ 2022年05月23日 11:23/ 0 赞/ 383 阅读
相关 大数相乘 def fun(num1,num2): num1 type str num2 type str a = map(int, 落日映苍穹つ/ 2021年10月24日 01:48/ 0 赞/ 382 阅读
还没有评论,来说两句吧...