#P4282. [AHOI2008] 计算器
[AHOI2008] 计算器
Description
Keke’s happy journey on Joy Island continues. He wants to buy some souvenirs for his classmates, so he goes to the gift shop and finds an interesting calculator.
This calculator is a special one that supports addition and subtraction of mixed-radix integers (mixed-radix means each digit can have a different base. For example, if the least significant digit uses base and the next digit uses base , then in this system converts to decimal as ).
The shopkeeper notices Keke’s interest and asks: “Kid, if I tell you this calculator supports mixed-radix integers of up to digits, and the bases for each digit are , do you know the maximum integer it can represent?” Keke thinks for a while and answers: “The maximum integer it can represent is .”
The shopkeeper is very happy and says: “You are a smart kid. If I give you two mixed-radix integers and of length , compute or as required, and give the answer in the same mixed-radix system. If you get it right, I will give you this calculator.”
This stumps Keke, but he really wants the calculator. Can you help him?
Input Format
- The first line contains an integer , the length of the mixed-radix numbers supported by the calculator.
- The second line contains integers , the bases of digits (from the most significant digit to the least significant digit).
- The third line contains integers , representing the first operand.
- The fourth line contains a character , representing the operation type.
- The fifth line contains integers , representing the second operand.
Output Format
If is '+', output . Otherwise, output . Separate digits with a single space, pad with leading zeros to digits, and do not print extra spaces before the most significant digit or after the least significant digit.
3
3 2 5
1 1 2
+
0 0 3
2 0 0
Hint
Constraints:
- For of the testdata, , .
- For of the testdata, , and .
Translated by ChatGPT 5
京公网安备 11011102002149号