美團校招 關燈問題&&7的倍數

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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章