AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 校园
  • 应用
  • 文章
    • 题解
    • 分享
    • 问答
  • 吐槽
  • 登录/注册

AcWing 794. 高精度除法

作者: 作者的头像   Kokaze ,  2022-01-16 11:35:00 ,  所有人可见 ,  阅读 5


0


#include<iostream>
#include<algorithm>
using namespace std;
vector<int> div(vector<int>&A,int b,int&t){
    t=0;
    vector<int>tmp;
    for(int i=A.size()-1;i>=0;i--){
        t = t*10 + A[i];
        tmp.push_back(t/b);
        t%=b;
    }

    reverse(tmp.begin(),tmp.end());
    while(tmp.size()>1 && tmp.back()==0)tmp.pop_back();
    return tmp;
}
int main(){
    string a;
    int b;
    cin>>a>>b;
    vector<int>A;
    for(int i=a.size()-1;i>=0;i--)A.push_back(a[i]-'0');
    int c;
    auto d = div(A,b,c);
    for(int i=d.size()-1;i>=0;i--)cout<<d[i];
    cout<<endl;
    cout<<c;
    return 0;
}

0 评论

你确定删除吗?
1024
x

© 2018-2022 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息