题目解析
给定n组a、b
判断a是爹、还是b是爹
判断条件:
去看b是否整除a的各位之和 或者 去看a是否能整除b的各位之和,这两个条件只能存在一个。
如果都存在或者都不存在,就看a和b谁大,谁大谁是爹
解题思路
先求一个各位之和
然后判断输出
代码
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
static int tosum(int x)
{
int ans = 0;
while (x > 0)
{
ans += x % 10;
x /= 10;
}
return ans;
}
public static void main(String[] args) throws IOException
{
int n = sc.nextInt();
while (n-- > 0)
{
int a = sc.nextInt(), b = sc.nextInt();
int sa = tosum(a), sb = tosum(b); // 先将各位之和求出来
if (a % sb == 0 && b % sa == 0)
out.println(a > b ? "A" : "B");
else if (a % sb == 0)
out.println("A");
else if (b % sa == 0)
out.println("B");
else
out.println(a > b ? "A" : "B");
}
out.flush();
out.close();
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
}