-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_B1022.cpp
More file actions
47 lines (41 loc) · 869 Bytes
/
3_B1022.cpp
File metadata and controls
47 lines (41 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* P94 进制转换
*/
#include <iostream>
#include <stack>
using namespace std;
int changeFunc(int value1, int value2, int product)
{
int sum = value1 + value2;
// initialize a stack
stack<int> modStack;
// 转换为D进制数
while (sum != 0)
{
modStack.push(sum % product);
sum /= product;
}
// 循环输出stack中的数 (余数)
int result = 0;
while (!modStack.empty())
{
// 为了输出格式
result *= 10;
result += modStack.top();
modStack.pop();
}
return result;
}
int main()
{
int value1, value2;
// 进制数
int product;
cout << "Input A, B: ";
cin >> value1 >> value2;
cout << "Input D: ";
cin >> product;
int result = changeFunc(value1, value2, product);
cout << "Output: " << result << endl;
return 0;
}