All problems

Problem 330

Compare Version Numbers

Medium · 20 pts · String, Two Pointers

Problem

A version number is a list of revisions separated by dots, such as 1.2.10. Compare two versions revision by revision from left to right, treating each revision as an integer (so leading zeros do not matter: '01' equals '1'). If one version has fewer revisions, the missing ones count as 0, so '1.0' equals '1'. Print -1 if the first version is smaller, 1 if it is larger, and 0 if they are equal.

Input

Two lines: the version strings V1 and V2.

Output

Print -1, 0 or 1.

Constraints

1 <= length <= 500; every revision fits in a 32-bit integer

Example input

1.01
1.001

Example output

0

Explanation

Comparing 1.01 and 1.001: the first revisions are 1 and 1, and the second revisions are 01 and 001, which are both the number 1. So the versions are equal and the answer is 0.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: String to Integer Next: Text Justification