80. Compare Two Strings
Foundation1000 ms256 MBSolved by 0%
Read two lines and compare them in dictionary order, character by character.
Print:
- -1 if the first line comes before the second
- 0 if they are identical
- 1 if the first line comes after the second
Comparison is by ASCII value, so all uppercase letters come before all lowercase ones. When one string is a prefix of the other, the shorter one comes first.
Constraints - Each line has between 1 and 100000 characters. - Printable ASCII only.
Input
Two lines, each containing one string.
Output
Print -1 if the first string comes before the second, 1 if it comes after, or 0 if they are equal.
Inputapple
banana
Output-1
Notediffers at the first character
Inputhello
hello
Output0
Noteis two identical strings
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution