首页 > 10.25美团笔试 求问第3题
头像
L-TANK
编辑于 2020-10-25 12:04
+ 关注

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;
    }
}


全部评论

(11) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

热门推荐