欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

1017 A除以B (20分)

程序员文章站 2022-06-07 14:19:54
...

1017 A除以B (20分)
输入样例:

123456789050987654321 7
输出样例:

17636684150141093474 3

# -*- coding: utf-8 -*-
import re


def big_division(a, b):
    q_list, r = [], 0

    len_a = len(a)
    for i in range(0, len_a):
        dividend = 10 * r + eval(a[i])
        q_list.append(dividend // eval(b))
        r = dividend % eval(b)
    if len(q_list) == 1 and q_list[0] == 0:
        return q_list[0], r
    q = eval(re.sub(r'^[0]{1,100}', '', ''.join(list(map(str, q_list)))))
    return q, r


if __name__ == '__main__':
    input_list = input().split()
    a = input_list[0]
    b = input_list[1]
    result = big_division(a, b)
    print(result[0], result[1])



相关标签: 算法修养