• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# course bouclée

roronoa Apr 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import java.util.*;
2. import java.io.*;
3. import java.math.*;
4. class Solution {
5.
6.     public static void main(String args[]) {
7.         Scanner in = new Scanner(System.in);
8.         int n = in.nextInt();
9.         int xTab[] = new int[n];
10.         int yTab[] = new int[n];
11.         for (int i = 0; i < n; i++) {
12.             xTab[i] = in.nextInt();
13.             yTab[i] = in.nextInt();
14.
15.         }
16.         double distance = 0;
17.         //double last = 0.0;
18.         int xLast =0;
19.         int yLast = 0;
20.         for(int i = 0; i < n-1; i++)
21.         {
22.              distance += Math.sqrt((xTab[i]-xTab[i+1])*(xTab[i]-xTab[i+1]) + (yTab[i]-yTab[i+1])*(yTab[i]-yTab[i+1]));
23.              if(i == n-2)
24.              {
25.                  xLast = xTab[i+1];
26.                  yLast = yTab[i+1];
27.              }
28.
29.         }
30.         distance += Math.sqrt( (xTab[0]-xLast)*(xTab[0]-xLast) + (yTab[0]-yLast)*(yTab[0]-yLast)  );
31.         int distanceI = (int) distance;
32.         if(distanceI - distance == 0)
33.             System.out.println(distanceI);
34.         else
35.         System.out.printf("%.3f",distance);
36.     }
37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top