Enter two non-negative decimal integers A and B ( ≤), the output A + B of the D ( . 1) binary number.
Input formats:
3 gives an integer input sequentially in a row A, B and D.
Output formats:
Output A + B of the D-nary number.
Sample input:
123 456 8
Sample output:
1103
#include <iostream> #include <stack> using namespace std; int main() { long long A,B;int D; cin>>A>>B>>D; long long sum=A+B; stack<int> sta; while(sum!=0){ sta.push(sum%D); sum/=D; } if(sta.empty()) cout<<0;/**0这个例外*/ while(!sta.empty()){ cout<<sta.top(); sta.pop(); } system("pause"); return 0; }