10.25美团笔试 求问第3题
我的代码一直输出错误,样例都过不了,是我的思路出问题了吗,求各位大佬解答 顺便求345AC代码 第4题骗分骗了0.27 完全没有思路
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int [] a = new int [n];
int [] b = new int [n];
for(int i = 0;i < n;i++)
{
a[i] = s.nextInt();
}
check(a,b);
}
public static void check(int [] a,int [] b)
{
for(int i = 0;i < b.length;i++)//计算bi的值
{
int temp1 = a[i];
for(int j = 0;j < a.length;j++)
{
int temp2 = (i + 1) % (j + 1);//mod
temp1 = func(temp1,temp2);
}
b[i] = temp1;
}
int res = b[0];
for(int i = 1;i < b.length;i++)
{
res = func(res,b[i]);
}
System.out.println(res);
}
public static int func(int a,int b)//异或运算
{
if(a == b) return 0;
return a;
}
}