1、热身计算
根据题意使用相关函数计算即可
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.printf("%d ",Math.min(a,b));
System.out.printf("%d ",Math.abs(a-b)/2);
}
}
2、比大小
根据进制计算每一位的和就好了
import java.util.Scanner;
public class Main{
static long sum1 = 0L;//注意需要设置long,不然会爆
static long sum2 = 0L;
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int bx = sc.nextInt();
int []x = new int[n];
for(int i = 0;i<n;i++){
x[i] = sc.nextInt();
}
for(int i = 0;i<n;i++){
sum1+=x[i]*(Math.pow(bx,n-i-1));//根据进制来计算每一位的和
}
int m = sc.nextInt();
int by = sc.nextInt();
int []y = new int[m];
for(int i = 0;i<m;i++){
y[i] = sc.nextInt();
}
for(int i = 0;i<m;i++){
sum2+=y[i]*(Math.pow(by,m-i-1));
}
if(sum1<sum2){
System.out.println("<");
}else if(sum1>sum2){
System.out.println(">");
}
else{
System.out.println("=");
}
}
}