题目描述
对于任意两个正整数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
输出
Equal
水题
package com.qiye;
import java.math.BigInteger;
import java.util.Scanner;
public class CircleNumCompare {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s1 = scanner.next();
int n = scanner.nextInt();
String s2 = scanner.next();
int m = scanner.nextInt();
s1 = repeat(s1,n);
s2 = repeat(s2,m);
BigInteger bg1 = new BigInteger(s1);
// System.out.println(bg1);
BigInteger bg2 = new BigInteger(s2);
// System.out.println(bg2);
if(bg1.compareTo(bg2) > 0){
System.out.println("Greater");
}
else if(bg1.compareTo(bg2) == 0){
System.out.println("Equal");
}
else{
System.out.println("Less");
}
}
public static String repeat(String s,int x){
String sub = s;
for(int i=0;i < x - 1;i ++){
s +=sub;
}
return s;
}
}