1.简述: 描述 对于任意两个正整数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,
1.简述:
描述对于任意两个正整数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输出:
Equal2.代码实现:
import java.math.BigInteger;import java.util.Scanner;
public class Main {
public static void main(String []args) {
Scanner input = new Scanner(System.in);
String a = input.nextLine();
String[] array = a.split(" ");
if(array.length != 4) {
System.out.println("输入不合法! " + array.length);
} else {
StringBuilder sb1 = new StringBuilder();
int k1 = Integer.valueOf(array[1]);
for (int i=0; i< k1; i++) {
sb1.append(array[0]);
}
StringBuilder sb2 = new StringBuilder();
int k2 = Integer.valueOf(array[3]);
for (int i=0; i< k2; i++) {
sb2.append(array[2]);
}
BigInteger v1 = new BigInteger(sb1.toString());
BigInteger v2 = new BigInteger(sb2.toString());
int num = v1.compareTo(v2);
if (num < 0) {
System.out.println("Less");
} else if (num == 0) {
System.out.println("Equal");
} else if (num > 0) {
System.out.println("Greater");
}
}
}
}