JAVA-蓝桥杯- 算法训练 生活大爆炸版石头剪刀布

题目略。
import java.util.Scanner;
 
 public class  Main{
     
     public static void f(int arr[],int arr1[],int a,int b,int num){
     
    	 int sumA = 0;int sumB=0;
    	 for (int j = 0,i=0,s=0; s <num; s++) {
     
			if ((arr[j]==0&&(arr1[i]==1||arr1[i]==4))  
				||(arr[j]==1&&(arr1[i]==2||arr1[i]==4))
				||(arr[j]==2&&(arr1[i]==0||arr1[i]==3))
				||(arr[j]==3&&(arr1[i]==0||arr1[i]==1))
				||(arr[j]==4&&(arr1[i]==2||arr1[i]==3))) {
     
				sumB+=1;
			}
			if ((arr[j]==0&&(arr1[i]==2||arr1[i]==3))
				||(arr[j]==1&&(arr1[i]==0||arr1[i]==3))
				||(arr[j]==2&&(arr1[i]==1||arr1[i]==4))
				||(arr[j]==3&&(arr1[i]==2||arr1[i]==4))
				||(arr[j]==4&&(arr1[i]==0||arr1[i]==1))) {
     
				sumA+=1;
			}
			if (j==a-1) {
       //当循环到第一周期最后一个是时候需要重新开始,
				j=-1;
			}
			if (i==b-1) {
      //当循环到第一周期最后一个是时候需要重新开始,
				i=-1;
			}
			j++;
			i++;
		}
    	System.out.print(sumA+" ");
		System.out.print(sumB);
     }
     public static void main(String[] args) {
     
         Scanner sc = new Scanner(System.in);
         int num = sc.nextInt();
         int A = sc.nextInt();
         int B = sc.nextInt();
         int arrA[]=new int[A];
         int arrB[]=new int[B];
         for (int i = 0; i <A; i++) {
     
			arrA[i]=sc.nextInt();
		}
         for (int i = 0; i <B; i++) {
     
 			arrB[i]=sc.nextInt();
 		} 
		f(arrA, arrB, A, B,num);
     }
 }

你可能感兴趣的:(JAVA蓝桥杯,java)