Cod sursa(job #2448145)

Utilizator dakataIonescu Valentin-Alexandru dakata Data 15 august 2019 21:11:46
Problema Aria Scor 60
Compilator java Status done
Runda Arhiva educationala Marime 1.65 kb


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.*;
import java.util.*;

/**
 *
 * @author dakata
 */
class Puncte {

    double x;
    double y;

    public Puncte(double x, double y) {
        this.x = x;
        this.y = y;
    }
}

public class Main {

    /**
     * @param args the command line arguments
     */
    /*
    public static void main(String[] args) throws FileNotFoundException {
        // TODO code application logic here
        Scanner scanner = new Scanner(new FileInputStream("adunare.in"));
        PrintStream writer = new PrintStream("adunare.out");
                
        int a = Integer.parseInt(scanner.nextLine());
        int b = Integer.parseInt(scanner.nextLine());
        writer.println(a+b);
        
    }
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {

        BufferedReader br = new BufferedReader(new FileReader("aria.in"));
        PrintStream writer = new PrintStream("aria.out");

        double sum = 0;
        int N = Integer.parseInt(br.readLine());
        Puncte[] puncte = new Puncte[N + 1];

        for (int i = 0; i < N; i++) {
            String line = br.readLine();
            String [] cuv = line.split(" ");
            puncte[i] = new Puncte(Double.parseDouble(cuv[0]), Double.parseDouble(cuv[1]));
        }
        puncte[N] = puncte[0];
        for (int i = 0; i < N; i++) {
            sum += puncte[i].x * puncte[i + 1].y - puncte[i + 1].x * puncte[i].y;
        }
        writer.printf("%.5f\n", sum / 2);
    }

}