코드비교

Old VersionNew Version
  1import java.util.Arrays; 
1import java.util.Scanner; 2import java.util.Scanner; 
2public class Main { 3public class Main { 
3public static void main(String[] args) { 4public static void main(String[] args) { 
4Scanner sc = new Scanner( System.in ); 5Scanner sc = new Scanner( System.in ); 
5int testNum = sc.nextInt(); 6int num = sc.nextInt();
6int[][] input = new int[4][2]; 7boolean[] square = new boolean[num];
7for (int i=0; i<testNum; i++) { 8int[][] arr = new int[4][2];
8for (int j=0; j<4; j++) 9for(int i=0; i<num; i++   ) {
9for (int k=0; k<2; k++) 10for(int j=0; j<4; j++) {
10input[j][k] = sc.nextInt(); 11arr[j][0] = sc.nextInt();
11System.out.println( isSquare(input)? "square" : "not square"); 12arr[j][1] = sc.nextInt();
   13}
   14square[i] = isSquare(arr);
   15}
   16for(boolean b:square) {
   17if(b==true) {
   18System.out.println("square");
   19}else {
   20System.out.println("not square");
12} 21} 
13} 22} 
14private static boolean isSquare(int[][] input) {   
15double[][] length = new double[6][2];   
16int index = 0;   
17for (int i=0; i<3; i++)   
18for (int j=i+1; j<4; j++) {   
19double temp = Math.pow(input[i][0]-input[j][0], 2) + Math.pow(input[i][1]-input[j][1], 2);   
20int k=0;   
21for (; k<index; k++)   
22if (temp == length[k][0]) {   
23length[k][1]++;   
24break;   
25} 23} 
26if (k == index) { 24static boolean isSquare(int[][] arr) {
27length[index][0] = temp; 25int[] length = new int[6];
28length[index][1]++; 26int a=0;
29index++; 27for(int i=0; i<arr.length-1;i++   ) {
   28for(int j=i+1; j<arr.length; j++) {
   29length[a] = (int)(Math.pow(arr[i][0]-arr[j][0], 2)+Math.pow(arr[i][1]-arr[j][1], 2));
   30a++;
30} 31} 
31} 32} 
32if (index != 2) 33for(int num:length) {
   34if(num == 0) {
33return false; 35return false; 
34if (length[0][1] != 4 && length[0][1] != 2) 36}
   37}
   38for(int i=0; i<length.length-1; i++) {
   39for(int j=0; j<length.length-1-i; j++) {
   40if(length[j] > length[j+1]) {
   41int temp = length[j];
   42length[j] = length[j+1];
   43length[j+1] = temp;
   44}
   45}
   46}
   47for(int i=0; i<4; i++) {
   48if(length[0] != length[i]) {
35return false; 49return false; 
  50} 
  51} 
  52for(int i=4; i<length.length; i++) { 
  53if(length[4] != length[i]) { 
  54return false; 
  55} 
  56} 
  57if(length[0]*2 != length[4]) { 
  58return false; 
  59} 
36return true; 60return true; 
37} 61} 
38} 62} 
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner( System.in );
int testNum = sc.nextInt();
int[][] input = new int[4][2];
for (int i=0; i<testNum; i++) {
for (int j=0; j<4; j++)
for (int k=0; k<2; k++)
input[j][k] = sc.nextInt();
System.out.println( isSquare(input)? "square" : "not square");
}
}
private static boolean isSquare(int[][] input) {
double[][] length = new double[6][2];
int index = 0;
for (int i=0; i<3; i++)
for (int j=i+1; j<4; j++) {
double temp  = Math.pow(input[i][0]-input[j][0], 2) + Math.pow(input[i][1]-input[j][1], 2);
int k=0;
for (; k<index; k++)
if (temp == length[k][0]) {
length[k][1]++;
break;
}
if (k == index) {
length[index][0] = temp;
length[index][1]++;
index++;
}
}
if (index != 2)
return false;
if (length[0][1] != 4 && length[0][1] != 2)
return false;
return true;
}
}
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
boolean[] square = new boolean[num];
int[][] arr = new int[4][2];
for(int i=0; i<num; i++	) {
for(int j=0; j<4; j++) {
arr[j][0] = sc.nextInt();
arr[j][1] = sc.nextInt();
}
square[i] = isSquare(arr);
}
for(boolean b:square) {
if(b==true) {
System.out.println("square");
}else {
System.out.println("not square");
}
}
}
static boolean isSquare(int[][] arr) {
int[] length = new int[6];
int a=0;
for(int i=0; i<arr.length-1;i++	) {
for(int j=i+1; j<arr.length; j++) {
length[a] = (int)(Math.pow(arr[i][0]-arr[j][0], 2)+Math.pow(arr[i][1]-arr[j][1], 2));
a++;
}
}
for(int num:length) {
if(num == 0) {
return false;
}
}
for(int i=0; i<length.length-1; i++) {
for(int j=0; j<length.length-1-i; j++) {
if(length[j] > length[j+1]) {
int temp = length[j];
length[j] = length[j+1];
length[j+1] = temp;
}
}
}
for(int i=0; i<4; i++) {
if(length[0] != length[i]) {
return false;
}
}
for(int i=4; i<length.length; i++) {
if(length[4] != length[i]) {
return false;
}
}
if(length[0]*2 != length[4]) {
return false;
}
return true;
}
}