Difficulty Level: Easy

Submissions: 4959 Accuracy:


String comparison

In a native language the increasing order of priority of characters is a, b, c, d, e, f, g, h, i, j, k, l, m, n, ’ng’ , o, p, q, r, s, t, u, v, w, x, y, z. You are given two strings string1 and string2 and your task is to compare them on the basis of the given priority order.

Print ‘0’ if both the strings are equal, ‘1’ if string1 is greater than string2 and ‘-1’ if string1 is lesser than string2. All the strings consist of lowercase English alphabets only.



The first line of the input contains a single integer T denoting the number of test cases. Each of the test case consists of a single line containing space separated two strings string1 and string2.


For each test case, print the required output in a new line.


1 <= T <= 1000

1 <= |string1, string2| <= 10^8




adding addio

abcng abcno

abngc abngc






Assume 0-based indexing.

For the 1st test case:

The Strings differ at index = 4. Comparing ‘ng’ and ‘o’, we have string1 < string2.

For the 2nd test case:

The Strings differ at index = 3. Comparing ‘ng’ and ‘n’, we have string1 > string2.

For the 3rd test case:

Both the strings are same.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sajal Agrawal
Author: sajalagrawal

Set Default Code

It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use, generate link and share the link here.