美团校招 关灯问题&&7的倍数

来源:互联网 发布:淘宝客服是干嘛的 编辑:程序博客网 时间:2024/05/01 18:46
package interview;import java.util.*;public class meituan {//关灯问题,看谁赢public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()){    int n = sc.nextInt();    int[] arr = new int[n];    for(int i = 0; i < n; i++)        arr[i] = sc.nextInt();    int res = 0;    for (int i = 0; i < n; i++){        if (arr[i] == 1 && res == 0){            res++;        }else if (arr[i] == 1 && (res%2 == 0)){            res++;        }else if (arr[i] == 0 && (res%2 != 0)){            res++;        }    }    if (res%2 != 0){    System.out.println("Alice");    }else{    System.out.println("Bob");    }}}}


public class meituan {//7的倍数public static void main(String[] args) {Scanner sc = new Scanner(System.in);        while(sc.hasNext()){            int n = sc.nextInt();            long[] nums = new long[n];            for(int i = 0; i < n; i++){                nums[i] = (long)sc.nextInt();            }            int num = 0;            for(int i = 0; i < n; i++){                for(int j = 0; j < n; j++){                    if(j == i) {                    continue;                    }                    long temp1 = Long.parseLong(nums[i]+""+nums[j]);                    if(temp1 % 7 == 0){                    num++;                    }                }            }            System.out.println(num);        }}}


原创粉丝点击