"Topic link"
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
Submit Code:
1#include <stdio.h>2#include <string.h>3 4 #defineMax_len (1024)5 6 voidDivision (Char*STR,intNChar*dest,int*R)7 {8 intDiv, q;9 intK, I, Len =strlen (str);Ten intFlag =0; One Adiv =0; -K =0; - for(i =0; i < Len; i++) the { -Div *=Ten; -div + = Str[i]-'0'; -Q = div/N; + if(Q >0) - { +dest[k++] = q +'0'; Adiv = div%N; atFlag =1; - } - Else if(q = =0&& Flag! =0) - { -dest[k++] = q +'0'; -div = div%N; in } - } to if(k = =0) + { -dest[k++] ='0'; the } *DEST[K] =' /'; $*r =Div;Panax Notoginseng } - the intMainvoid) + { A CharDest[max_len]; the CharStr[max_len]; + intN, R; - $ //printf ("Input str: \ r \ n"); $scanf"%s", str); - //printf ("Input n: \ r \ Nand"); -scanf"%d", &n); the //printf ("%s/%d =\r\n", str, n); - Wuyimemset (dest,0x00,sizeof(dest)); theDivision (STR, n, dest, &R); -printf"%s%d", dest, R); Wu return 0; -}
PAT (Basic level) practise:1017. A divided by B (20)