#C13119. Compare Version Strings
Compare Version Strings
Compare Version Strings
You are given two version strings version1 and version2. A version string is composed of numeric parts separated by a dot ("."). Your task is to compare these two strings.
If version1 is less than version2, print -1.
If they are equal, print 0.
If version1 is greater than version2, print 1.
Formally, let the version strings be represented as \[ \text{version1} = a_1.a_2.\dots.a_n,\quad \text{version2} = b_1.b_2.\dots.b_m, \] where each a_i and b_j are non-negative integers. Treat missing parts as 0 and compare lexicographically, i.e. find the smallest index k such that \(a_k \neq b_k\). Output the result accordingly.
inputFormat
The input consists of two lines. The first line contains a version string version1, and the second line contains version2.
Each version string contains digits and dots (.
) only.
outputFormat
Output a single integer, which is:
- -1 if version1 is less than version2,
- 0 if they are equal,
- 1 if version1 is greater than version2.
1.0.0
1.0.1
-1
</p>