Links: http://www.nowcoder.com/pat/6/problem/4043
Title Description
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 Description:
The input is given a and B in 1 rows, and the middle is separated by 1 spaces.
Output Description:
In 1 rows, output Q and R in turn, separated by 1 spaces in the middle.
Input Example:
123456789050987654321 7
Output Example:
17636684150141093474 3
1#include"iostream"2#include <iomanip>3#include <string.h>4#include <string>5#include <vector>6#include <cmath>7#include <cctype>8#include <algorithm>9 using namespacestd;Ten One intD, R, I; A intnum1[ +]; - intnum2[ +]; - Charstr[ +]; the intMain () - { -CIN >>str >>D; - for(i=0; I<strlen (str); ++i) + { -Num1[i] = str[i]-'0'; + } AI=1; at intk=0, tmp=num1[0]; - while(I <strlen (str)) - { -TMP = tmp*Ten+num1[i++]; - if(tmp > D) Break; - } in while(I <=strlen (str)) - { tonum2[k++] = tmp/D; +TMP%=D; -TMP = tmp*Ten+num1[i++]; the } *r = tmp/Ten; $ for(intI=0; i<k; ++i)Panax Notoginseng { -cout <<Num2[i]; the } +cout <<" "<<r <<Endl; A return 0; the}
A divided by B