Comparing Version Strings
Your team's deployment tool refuses to roll out a build unless it is newer than the one already
running. Release versions are written as dotted strings like 1.02.10 or 2.0.0.7, but they come
from many different build pipelines, and those pipelines disagree about formatting: some pad
components with leading zeros, some drop trailing .0 parts, and one nightly pipeline stamps a
full timestamp-plus-hash number into a single component, up to 50 digits long.
Versions are compared as follows:
- A version is a sequence of components, separated by dots. Each component is a non-negative
integer written in decimal, possibly with leading zeros, so
01,001and1all mean the same number, and000means0. - If one version has fewer components than the other, it is extended with components equal to
0until both have the same count. So1.2,1.2.0and1.02.0.00are all equal. - The versions are then compared component by component from left to right. The first position where the numbers differ decides: the version with the smaller number there is older. If no position differs, the versions are equal.
You are given q pairs of versions. For each pair, report how the first version relates to the
second.
Input
The first line contains an integer q (1 ≤ q ≤ 10^5), the number of pairs.
Each of the next q lines contains two version strings a and b, separated by a single space.
Every version string consists of one or more components separated by single dots. Every component
is a non-empty string of between 1 and 50 decimal digits (0–9). There are no other characters:
no leading or trailing dots, no two consecutive dots, no signs. Each version string has length at
most 200, and the total length of all 2q version strings is at most 4·10^6.
Output
Print q lines. On the i-th line print older if the first version of the i-th pair is older
than the second, newer if it is newer, and equal if the two versions are equal.
Notes
In the first example:
1.02.10vs1.2.9.0: the first components are both 1, the second are both 2, and in the third 10 > 9, so the first version isnewer.1.0vs1.0.0.0: the missing components count as 0, so the versions areequal.0.9vs0.10: 9 < 10 as numbers, so the first version isolder, even though the string9sorts after10alphabetically.3vs3.0.1: the first version is extended to3.0.0, and 0 < 1 in the last component.
A component may have up to 50 digits, which does not fit in a 64-bit integer.