PAT B1017大整数相除(除数小于10)

// 2019 3 16.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <iostream>
using namespace std;

typedef struct bign{
	int s[1010];
	int len;
	bign(){
		fill(s,s+1010,0);
		len = 0;
	}
};

bign convert(char str[]){
	bign a;
	int len = strlen(str);
	a.len = len;

	for(int i = 0;i<len;i++){
		a.s[i] = str[i]-'0';
	}

	return a;
}

bign dashuchufa(bign a,int b,int &r){

     bign c;
	 c.len = a.len;

	 for(int i = 0;i<a.len;i++){
		 r = r*10+a.s[i];

		 if(r<b){
			 c.s[i] = 0;
		 }else{
			 c.s[i] = r/b;
			 r = r%b;
		 }
	 }

	 return c;
}

int _tmain(int argc, _TCHAR* argv[])
{
	char str[1010]; int b;

	scanf("%s%d",str,&b);

	bign a = convert(str);

	
	int r = 0;
	bign c = dashuchufa(a,b,r);

	int i,j;
	for(i = 0;i<c.len;i++){

		j = 0;
		while(c.s[j] == 0 && j<c.len){
			j++;
		}
		if(j == c.len){
			printf("0 %d\n",r);
			//system("pause");
			return 0;
		}
	}

	for(i = j;i<c.len;i++){
		printf("%d",c.s[i]);
	}
	printf(" %d\n",r);

	//system("pause");
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值