The subject requires a A/b, where A is a positive integer that does not exceed 1000 bits, and B is a 1-bit positive integer. You need to output the quotient Q and the remainder r so that a = B * Q + R is set up.
Input format:
The input is given a and B in 1 rows, and the middle is separated by 1 spaces.
Output format:
In 1 rows, output Q and R in turn, separated by 1 spaces in the middle.
Input Sample:
123456789050987654321 7
Sample output:
17636684150141093474 3
Idea: Be sure to pay attention to the connection between input variables
1#include <iostream>2 using namespacestd;3#include <string.h>4#include <stdio.h>5 intMainintargcChar*argv[])6 {7 Charnumber[1010];8 Charresul[1010]; 9 CharChushu;TenCin>>number>>Chushu; One BOOLflag=true;//number of first digits A intj=0; - intReminder=0; - intb=chushu- -; the for(intI=0; number[i]!=' /'; i++) - { - inta=number[i]- -; -a=reminder*Ten+A; + intc=a/B; - intd=a%B; + //cout<<c<<endl<<d<<endl; A if(flag) at { -flag=false; - if(c>0) -resul[j++]=c+ -; - Else if(c==0&&number[1]==' /') -resul[j++]=c+ -; inReminder=D; - Continue; to } + Else - { theresul[j++]=c+ -; *Reminder=D; $ Panax Notoginseng } - } theresul[j]=' /'; +printf"%s%d\n", Resul,reminder); A return 0; the}
View Code
PAT1017. A divided by B (20)