问题描述
"A"<"B"
"a">"A"
"computer">"compare"
"hello"<"helloworld"
样例输出
数据规模和约定
字符串长度<100。
代码如下:
package ADV_227;
import java.util.Scanner;
public class Main {
public static void cmp(char c1[],char c2[]){
int length1=c1.length;
int length2=c2.length;
int i=0;
int j=0;
int res=0;
while(i<length1&&j<length2){
res=c1[i]-c2[j];
i++;
j++;
if(res!=0)
break;
}
if(res>0)
System.out.print(1);
else if(res<0)
System.out.print(-1);
else{
int temp1=length1-i;
int temp2=length2-j;
if(temp1==temp2)
System.out.print(0);
else if(temp1>temp2)
System.out.print(1);
else
System.out.print(-1);
}
}
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
String s1=cin.next();
String s2=cin.next();
char c1[]=s1.toCharArray();
char c2[]=s2.toCharArray();
cmp(c1,c2);
}
}