PAT Class B 1022D system A+B 20 (minutes)

topic

Enter two non-negative decimal integer AA A and BB B ( ≤ 2. 3 0?. 1 \ 2 ^ {30} Le -1 2 ? . 3 0 ? ? ? . 1 ), the output A + B A + B A + B ’s DD D ( 1 <D ≤ 1 0 1 <D \le 10 1 < D 1 0 ) hexadecimal number.

Input format:

In the given input row sequentially three integers AA A , BB B , and DD D .

Output format:

Output A + B A + B A + B of DD D nary.

Input sample:

123 456 8

Sample output:

1103

Code


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    
    
	int i, j, sum, bit,LEN;
	cin >> i >> j >> bit;
	sum = i + j;
	for (i = 0;; i++)
		if (sum < pow(bit, i))
			break;
	LEN = i;
	int* a = new int[LEN];
	for (i = LEN - 1; i >= 0; i--)
	{
    
    
		a[i] = sum % bit;
		sum = sum / bit;
	}
	if (LEN == 0)
		cout << "0";
	for (i = 0; i < LEN; i++)
		cout << a[i];
	return 0;
}

Question details link

Guess you like

Origin blog.csdn.net/qq_41985293/article/details/114983204