Skip to main content
Back to problems
Codeforces
Easy
Strings
Sorting
Petya and Strings

Compare two strings case-insensitively and output their lexicographic relationship.

Acceptance 0%
Problem Statement

Problem

You are given two strings of the same length. Compare them ignoring case and determine their lexicographic order.

  • If the first string is lexicographically smaller, print -1.
  • If the second string is lexicographically smaller, print 1.
  • If they are equal, print 0.

The comparison is made after converting both strings to the same case. In this problem, think of lowercase letters as being equal to their uppercase counterparts.

Notes

  • The strings contain only English letters.
  • Comparison is performed character by character from left to right.
  • The first differing character decides the answer.

Input Format

  • One line containing the first string s.
  • One line containing the second string t.

Output Format

Print one integer:

  • -1 if s < t
  • 1 if s > t
  • 0 if s = t

The comparison is case-insensitive.

Constraints

  • 1 <= |s|, |t| <= 100
  • |s| = |t|
  • s and t consist only of Latin letters.
Examples
Sample cases returned by the problem API.

Example 1

Input

aaaa
AAAA

Output

0

Explanation

After ignoring case, both strings are identical.

Example 2

Input

abcdef
ABCDEF

Output

0

Explanation

The strings are equal when compared case-insensitively.

Show 1 more example

Example 3

Input

aaaa
zzzz

Output

-1

Explanation

At the first position, a comes before z.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.