A. Petya and Strings | codeforces 112A | iamAvX
A. Petya and Strings
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
- import java.util.Scanner;
- /**
- *
- * @author abhishekraj
- */
- public class Code {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner sc = new Scanner(System.in);
- java.lang.String str1 = sc.nextLine();
- java.lang.String str2 = sc.nextLine();
- str1 = str1.toLowerCase();
- str2 = str2.toLowerCase();
- int m=0;
- int p1 = 0,p2 = 0;
- for(int n=0;n<str1.length();n++)
- {
- char c1 = str1.charAt(n);
- char c2 = str2.charAt(m);
- p1 = (int)c1;
- p2 = (int)c2;
- if(p1<p2)
- {
- break;
- }
- else if(p1>p2)
- {
- break;
- }
- else
- {
- m++;
- }
- }
- if(p1<p2)
- {
- System.out.println("-1");
- }
- else if(p1>p2)
- {
- System.out.println("1");
- }
- else
- {
- System.out.println("0");
- }
- }
- }
Comments
Post a Comment