AcWing 794. JAVA:高精度除法
原题链接
简单
作者:
ARM
,
2020-08-03 15:13:22
,
所有人可见
,
阅读 325
java 代码
import java.io.*;
import java.util.ArrayList;
class Main{
static int mod = 0;
static ArrayList<Integer> divString(ArrayList<Integer> a, int b){
ArrayList<Integer> c = new ArrayList<>();
for(int i = 0; i < a.size(); ++i){
mod = mod * 10 + a.get(i);
if(mod >= b){
c.add(mod / b);
}else{
c.add(0);
}
mod %= b;
}
while(c.size() > 1 && c.get(0) == 0)c.remove(0);
return c;
}
public static void main(String[] args)throws Exception{
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String a = buf.readLine();
String b = buf.readLine();
ArrayList<Integer> list = new ArrayList<>();
for(int i = 0; i < a.length(); ++i){
list.add(a.charAt(i) - '0');
}
int num = Integer.valueOf(b);
ArrayList<Integer> list1 = divString(list, num);
for(int n : list1){
System.out.print(n);
}
System.out.println();
System.out.print(mod);
}
}