Import Java.util.Arrays;
/**
* Today to do the American group's pen test, encountered this problem, took a little time to deal with;
* The code implements the basic function, many boundary problems are not considered
* The following issues exist
* 1, positive negative numbers are not considered;
* 2. If the quotient is a large number then the code result will be wrong.
*
* @author Liu Zhongwu
*
*/
public class Solution {
public void div (string A, string b) {
char[] Chara = A.tochararray ();
char[] Charb = B.tochararray ();
int[] numa = new Int[a.length ()];
int[] numb = new int[b.length ()];
for (int i = 0; i < charb.length; i++) {
Numb[i] = charb[i]-' 0 ';
}
for (int i = 0; i < chara.length; i++) {
Numa[i] = chara[i]-' 0 ';
}
int div=0;
while (compare (Numa,numb) >0) {
Numa= Div (numa,numb);
div + +;
}
StringBuffer sb = new StringBuffer ();
Sb.append ("+div+");
for (int i = 0; i < numa.length; i++) {
Sb.append ("+numa[i");
}
System.out.println ("+SB");
}
Private int[] Div (int[] numa, int[] numb) {
for (int i = 0; i < numb.length; i++) {
int tmpa = numa[numa.length-i-1];
int TMPB = numb[numb.length-i-1];
int sub = TMPA-TMPB;
int count = numa.length-1;
if (sub>=0) {
NUMA[NUMA.LENGTH-I-1] = Sub;
}else{
Numa[numa.length-i-1] = sub+10;
Count =numa.length-i-1-1;
while (numa[count]==0) {
Numa[count] = 9;
count--;
}
numa[count]--;
if (numa[0]==0) {
NUMA = Arrays.copyofrange (numa,1, numa.length);
}
}
}
return NUMA;
}
int compare (int[] numa, int[] numb) {
if (numa.length<numb.length) {
return-1;
}else if (numa.length>numb.length) {
return 1;
}else{
for (int i = 0; i < numb.length; i++) {
if (Numa[i]>numb[i]) {
return 1;
}
if (Numa[i]<numb[i]) {
return-1;
}
}
return 0;
}
}
}
Large number of divisions do not use BigInteger Java implementations