코드비교

Old VersionNew Version
  1import java.util.Scanner; 
1import java.util.Arrays; 2import java.util.Arrays; 
2import java.util.Scanner; 2import java.util.Comparator;
3public class Main { 4public class Main { 
4public static void main(String[] args) { 5public static void main(String[] args) { 
5Scanner input = new Scanner(System.in); 6int n;
6int T = input.nextInt(); 7Scanner sc = new Scanner(System.in);
7int [] dot = new int [8]; 8n = sc.nextInt();
8double [] a = new double [6]; 9sc.nextLine();
9for(int i = 0 ; i<T ; i++) { 10int p1[][] = new int[4][2] ;
10for(int j=0; j<8; j++) { 11for(int i = 0 ; i < n ; i++) {
11dot[j] = input.nextInt(); 12for(int j = 0 ; j < 4 ; j++) {
   13int x = sc.nextInt() ;
   14int y = sc.nextInt() ;
   15p1[j][0] = x ;
   16p1[j][1] = y ;
12} 17} 
13int N =0; 18sc.nextLine() ;
14while(N<6) { 19boolean t = true ;
15for(int j = 0 ;j<=4 ;j=j+2) { 20for(int j = 0 ; j < 4 ; j++) {
16for(int k = j+2; k<=6; k=k+2) { 21double a = 0 ;
17a[N]=Math.sqrt((dot[j]-dot[k])*(dot[j]-dot[k])+(dot[j+1]-dot[k+1])*(dot[j+1]-dot[k+1])); 22double b = 0 ;
18N++; 23for(int k = 0 ; k < 4 ; k++) {
   24if (j == k)
   25continue ;
   26double dis = Math.sqrt(Math.pow(Math.abs(p1[j][0] - p1[k][0]), 2 )+
   27Math.pow(Math.abs(p1[j][1] - p1[k][1]), 2));
   28// System.out.println(dis);
   29if (dis == 0)
   30t = false ;
   31if(a == 0 ) {
   32a = dis ;
   33}
   34else if(a != dis && b == 0) {
   35b= dis ;
   36}
   37else if(b != dis && a!= dis)
   38t = false ;
   39// System.out.println(a + " " + b);
19} 40} 
20} 41} 
21} 21if(t) {
22Arrays.sort(a);   
23if(a[0]==0&&a[5]==0) {   
24System.out.println("not square");   
25}   
26else {   
27if(a[0]==a[1]&&a[0]==a[2]&&a[0]==a[3]) {   
28if(a[4]==a[5]) {   
29System.out.println("square"); 43System.out.println("square"); 
30}   
31else {   
32System.out.println("not square");   
33}   
34} 44} 
35else { 45else { 
36System.out.println("not square"); 46System.out.println("not square"); 
  
38} 48} 
39} 49} 
40} 50} 
41}   
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
int [] dot = new int [8];
double [] a = new double [6];
for(int i = 0 ; i<T ; i++) {
for(int j=0; j<8; j++) {
dot[j] = input.nextInt();
}
int N =0;
while(N<6) {
for(int j = 0 ;j<=4 ;j=j+2) {
for(int k = j+2; k<=6; k=k+2) {
a[N]=Math.sqrt((dot[j]-dot[k])*(dot[j]-dot[k])+(dot[j+1]-dot[k+1])*(dot[j+1]-dot[k+1]));
N++;
}
}
}
Arrays.sort(a);
if(a[0]==0&&a[5]==0) {
System.out.println("not square");
}
else {
if(a[0]==a[1]&&a[0]==a[2]&&a[0]==a[3]) {
if(a[4]==a[5]) {
System.out.println("square");
}
else {
System.out.println("not square");
}
}
else {
System.out.println("not square");
}
}
}
}
}
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
public class Main {
public static void main(String[] args) {
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
sc.nextLine();
int p1[][] = new int[4][2] ;
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j < 4 ; j++) {
int x = sc.nextInt() ;
int y = sc.nextInt() ;
p1[j][0] = x ;
p1[j][1] = y ;
}
sc.nextLine() ;
boolean t = true ;
for(int j = 0 ; j < 4 ; j++) {
double a = 0 ;
double b = 0 ;
for(int k = 0 ; k < 4 ; k++) {
if (j == k)
continue ;
double dis = Math.sqrt(Math.pow(Math.abs(p1[j][0] - p1[k][0]), 2 )+
Math.pow(Math.abs(p1[j][1] - p1[k][1]), 2));
//  System.out.println(dis);
if (dis == 0)
t = false ;
if(a == 0 ) {
a = dis ;
}
else if(a != dis && b == 0) {
b= dis ;
}
else if(b != dis && a!= dis)
t = false ;
//  System.out.println(a + " " + b);
}
}
if(t) {
System.out.println("square");
}
else {
System.out.println("not square");
}
}
}
}