QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#251. 古代数字

統計

最近的考古发现揭示了一种类似于罗马数字的古代数字系统。这些数字由字母 H、Z、Y、G、T、R 和 I 表示。进一步的研究揭示了它们的值:

H = 9261
Z = 1323
Y = 441
G = 63
T = 21
R = 3
I = 1

此外,还发现这些古代数字也包含像罗马数字那样的十二进制分数:

1/12 = .
2/12 = ..
3/12 = ...
4/12 = ....
5/12 = .....
6/12 = S
7/12 = S.
8/12 = S..
9/12 = S...
10/12 = S....
11/12 = S.....

表示数字的字符按从高到低的顺序排列,表示这些字符值的相加,因此 HZYGTRI = 11,113。如果一个较小值的字符出现在较大值字符之前,则进行减法运算。除 H 外,任何字符在序列中重复次数不得超过五次。只有当序列会导致六个或更多重复字符时,才允许减去下一个较小的数字,例如 IR 不代表 2,因为 2 可以表示为 II,无需减法且无需重复 I 字符 6 次或以上。必须使用较高值的字符来代替多个重复的较低值字符,例如 TTT 是无效的,因为可以使用 G 代替。

你将收到一系列古代数字以及对它们执行的运算(加、减、乘或除)。每个测试用例恰好包含一个运算。

输入和输出中的所有古代数字长度均小于 25 个字符,且范围在 $0 < V < 175\,000\,000$ 之间。

小于 1/12 的分数应舍弃,即向下取整到最接近的 1/12。

输入的第一行包含测试用例的数量 $T$ ($1 \leq T \leq 50$)。每个测试用例将是一个有效的古代数字字符串,紧接着是一个运算符号(+-*/),然后再接另一个有效的古代数字字符串。

你的输出应显示运算结果,并以有效的古代数字字符串形式呈现。

样例

输入格式 1

3
H-I
ZZZZTTRRRRI/RRRR
Y*R

输出格式 1

ZHYYGYTTRTII
YRIS.
Z

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.