对于任意两个正整数x和k,我们定义repeat(x, k)为将x重复写k次形成的数,例如repeat(1234, 3) = 123412341234,repeat(20,2) = 2020.
牛牛现在给出4个整数x1, k1, x2, k2, 其中v1 = (x1, k1), v2 = (x2, k2),请你来比较v1和v2的大小。
输入描述:
输入包括一行,一行中有4个正整数x1, k1, x2, k2(1 ≤ x1,x2 ≤ 10^9, 1 ≤ k1,k2 ≤ 50),以空格分割
输出描述:
如果v1小于v2输出”Less”,v1等于v2输出”Equal”,v1大于v2输出”Greater”.
输入例子1:
1010 3 101010 2
输出例子1:
Equal
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int x1 = in.nextInt();
int k1 = in.nextInt();
int x2 = in.nextInt();
int k2 = in.nextInt();
String str = equalsTwoNum(x1,k1,x2,k2);
System.out.println(str);
}
public static String equalsTwoNum(int x1,int k1,int x2,int k2) {
String str = "Equal";
if(k1 == k2) {
str = x1>x2?"Greater":(x1==x2?"Equal":"Less");
}else {
StringBuffer x11 = new StringBuffer(x1+"");
StringBuffer x22 = new StringBuffer(x2+"");
if(x11.length()*k1 > x22.length()*k2) {
str = "Greater";
}else if(x11.length()*k1 < x22.length()*k2){
str = "Less";
}else if(x11.length()*k1 == x22.length()*k2){
for(int i = 0; i < k1; i++) {
x11.append(x1);
}
for(int i = 0; i < k2; i++) {
x22.append(x2);
}
for(int i = 0; i < x11.length(); i++) {
if(x11.charAt(i) != x22.charAt(i)) {
int x111 = x11.charAt(i);
int x222 = x22.charAt(i);
str = x111>x222?"Greater":"Less";
break;
}
}
}
}
return str;
}
}