Topic describes

Input two non-negative 10 base integers A and B (≤2^30−1), and output the D (1<D≤10) base number of A+B. Input format: Input gives three integers A, B, and D in A row.

Output format: Output the D base number of A+B.

Example Value: 123 456 8 Example value: 1103

Analysis of ideas,

The figure below illustrates the conversion from decimal to binary by iterating a decimal number by D iterating the remainder of the decimal number in reverse order is the base number to be converted

AC code

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long a,b,d,n;
    int x[1000] = {0};
    cin>>a>>b>>d;
    n=a+b;
    if(n==0)// Note that this is a special test point!
    {
        cout<<0;
        return 0;
    }
    int i=0;
    while(n! =0)
    {
        x[i++]=n%d;
        n/=d;
    }
    while(i--)
        cout<<x[i];
    return 0;
}
Copy the code

Conclusion comprehension

Perseverance, stone can be used to sleep first, rest and then brush tomorrow!