文章
2
粉丝
89
获赞
2
访问
2.4k
// Created by JZhang
#include <bits/stdc++.h>
using namespace std;
void divide(int a[], int b, int Q[], int len){
    int t=0, r, temp=a[0];
    for(int i=0; i<len; i++){
        Q[i]=temp/b;
        r=temp%b;
        temp=r;
        if(temp<b) temp=r*10+a[i+1]; //每次相除的余数小于b的话需要再补一位 
    }
    //计算前导0的数量 
    for(int i=0; i<len; i++){
    	if(Q[i]==0) t++;
    	else break;
	}
    for(int i=t; i<len; i++)
        cout<<Q[i];
    cout<<" "<<r<<endl;
}
int main(){
    string A;
    int R, b;
    while(cin>>A>>b){	
    	int len=A.length();
    	int* a=new int[len];
    	int* Q=new int[len];
    	for(int i=0; i<len; i++)
        	a[i]=A[i]-'0';      //数组a存放被除数的每一位 
    	divide(a, b, Q, len);
	}
}
登录后发布评论
暂无评论,来抢沙发