Advertisement
jenrus

Задача №3176. Ферзи (только 1, 4, 5)

Oct 19th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class hw2{
  4.     public static void main(String[] args){
  5.         Scanner scan = new Scanner(System.in);
  6.         int[] a = new int[16];
  7.         //placeholder for arraycopy
  8.         int[] b = new int[16];
  9.         //eating counter
  10.         int f = 0;
  11.         for(int i=0; i<a.length; i++){
  12.             a[i]=scan.nextInt();
  13.         }
  14.         for(int i=0; i<a.length; i++){
  15.             //verticales
  16.             boolean c = a[0]==a[2]&&a[0]==a[4]&&a[0]==a[6]&&a[0]==a[8]&&a[0]==a[10]&&a[0]==a[12]&&a[0]==a[14];
  17.             //horizontales
  18.             boolean d = a[1]==a[3]&&a[1]==a[5]&&a[1]==a[7]&&a[1]==a[9]&&a[1]==a[11]&&a[1]==a[13]&&a[1]==a[15];
  19.             //diagonales
  20.             boolean e = Math.abs(a[2]-a[0])==Math.abs(a[3]-a[1])&&Math.abs(a[4]-a[0])==Math.abs(a[5]-a[1])&&Math.abs(a[6]-a[0])==Math.abs(a[7]-a[1])&&Math.abs(a[8]-a[0])==Math.abs(a[9]-a[1])&&Math.abs(a[10]-a[0])==Math.abs(a[11]-a[1])&&Math.abs(a[12]-a[10])==Math.abs(a[13]-a[1])&&Math.abs(a[14]-a[0])==Math.abs(a[15]-a[1]);
  21.             //check
  22.             if(c&d&e){
  23.                 f++;
  24.             }
  25.             System.arraycopy(a, 0, b, 2, 14);
  26.             System.arraycopy(a, 14, b, 0, 2);
  27.             System.arraycopy(b, 0, a, 0, 16);
  28.  
  29.         }
  30.         if(f>0){
  31.             System.out.println("YES");
  32.         }else{
  33.             System.out.println("NO");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement