PAT1022. D-in A+b (20)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.