
You are given a character ‘CH’ as input, return either 1, 0 or -1 according to the following rules:
1, if the character is an uppercase alphabet (A - Z).
0, if the character is a lowercase alphabet (a - z).
-1, if the character is not an alphabet.
For Example :If ‘CH’ = ‘a’, then since it is a lowercase letter, your program should return 0.
The first line contains a single integer T representing the number of test cases.
The first line and only line of each test case contains the character ‘CH’.
Output Format :
For each test case, print 1 or 0 or -1 as discussed above.
Output for every test case will be printed in a separate line.
Note:
You don’t need to print anything. It has already been taken care of.
1 <= T <= 10
‘CH’ = ASCII character
Time Limit: 1 sec
2
A
t
1
0
For sample case 1, ‘A’ is an uppercase letter, hence output is 1.
For sample case 2, ‘t’ is a lowercase letter, hence output is 0.
2
#
P
-1
1
For sample case 1, ‘#’ is not an alphabet, hence output is -1.
For sample case 2, ‘P’ is an uppercase letter, hence output is 1.
Can you check in which range of characters ‘CH’ lie to check its type?
The idea is to simply check in what range the character ‘CH’ lies to find its type. For example, lowercase letters must lie in the range of ‘a’ to ‘z’ and uppercase letters must lie in the range of ‘A’ to ‘Z’.
Here is the algorithm:
O(1)
Since no loop is used, total time complexity is O(1).
O(1)
Since, we are not using any extra space for solving this problem, effective space complexity is O(1).