Enter two non-negative 10 binary integers A and B (<=230-1) and Output a+b D (1 < D <= 10) of the binary number.
Input format:
The input gives 3 integers a, B, and D, in turn, in one row.
Output format:
The D binary number of the output a+b.
Input Sample:
123 456 8
Sample output:
1103
Note: D-binary, use the stack should be aware of the namespace.
1#include <stdio.h>2#include <stack>3 using namespacestd;4 /*5 Char str1[35];6 Char str2[35];7 void Reverse (char str1 [])8 {9 Char str[35];Ten for (int i=0;i<strlen (STR1); i++) One { A Str[i] =str1[i]; - } - for (int i=0;i<strlen (STR1); i++) the { - Str1[strlen (STR1) -1-i]=str[i]; - } - }*/ + intMainintargcChar**argv) - { + inta,b,d; Astack<int>S; at //reverse the two numbers -scanf"%d%d%d",&a,&b,&D); - intsum=a+B; - while(sum>=D) - { - intreminder=sum%D; insum=sum/D; - S.push (reminder); to } + s.push (sum); - while(!s.empty ()) the { *printf"%d", S.top ()); $ S.pop ();Panax Notoginseng } - the return 0; +}
View Code
PAT1022. D-in A+b (20)