curiouscurrent's blog

By curiouscurrent, history, 15 months ago, In English

14C - Four Segments

I am getting compilation error. Please help. Thankyou.

This is my code.

import java.util.*; import java.io.*;

public class Main {

static StringBuilder sb;
Scanner scan = new Scanner(System.in);

static void solve()
{
    int[] x1 = new int[4];
    int[] y1 = new int[4];
    int[] x2 = new int[4];
    int[] y2 = new int[4];

    int hor=0;
    int ver=0;
    for(int i=0; i<4; i++)
    {
        x1[i] = scan.nextInt();
        y1[i] = scan.nextInt();
        x2[i] = scan.nextInt();
        y2[i] = scan.nextInt();

        if(x1[i]-x2[i]==0)
        {
            ver++;
        }
        if(y1[i]-y2[i]==0)
        {
            hor++;
        }

    }

    int count=0;
    for(int i=0; i<3; i++)
    {
        for(int j=i+1; j<4; j++)
        {
            if(x1[i]==x2[j] && y1[i]==y2[j])
            {
                count++;
            }
            if(x1[i]==x1[j] && y1[i]==y1[j])
            {
                count++;
            }
            if(x1[i]==x1[j] && y2[i]==y1[j])
            {
                count++;
            }
            if(x2[i]==x2[j] && y2[i]==y2[j])
            {
                count++;
            }
        }
    }

    if(ver==2 && hor==2 && count==4)
    {
        System.out.println("YES");
    }
    else
    {
        System.out.println("NO");
    }
}

public static int[] readArray(int n)
{
    int A[] = new int[n];
    for(int i=0; i<n; i++)
    {
            A[i] = scan.nextInt();
    }
    return A;
}

public static void main(String args[])
{


    try
    {
        Main obj = new Main();
        obj.run (args);
    }
     catch (Exception e)
    {
        e.printStackTrace ();
    }

    void run (String[] args)
    {
        // sb = new StringBuilder();
        int test = 1;
        while(test-- >0)
        {
            solve();
        }
    // System.out.println(sb);

    }
}

}

  • Vote: I like it
  • -7
  • Vote: I do not like it

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Auto comment: topic has been updated by curiouscurrent (previous revision, new revision, compare).

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Auto comment: topic has been updated by curiouscurrent (previous revision, new revision, compare).