Advertisement
anhkiet2507

KhoangCachVaTichVoHuong

Oct 19th, 2022
1,767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package ktgk2;
  7.  
  8. import java.util.*;
  9.  
  10. /**
  11.  *
  12.  * @author nguyenanhkiet
  13.  * Khoang cach va tich vo huong
  14.  */
  15. public class KTGK2 {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21.         Scanner cin = new Scanner(System.in);
  22.         int t = Integer.parseInt(cin.nextLine());
  23.         while(t-->0){
  24.             String s1 = cin.nextLine();
  25.             String st1[] = s1.trim().split("\\s+");
  26.             int amount1 = st1.length;
  27.             double arr1[] = new double[amount1];
  28.             for(int i = 0; i < amount1; i++){
  29.                 arr1[i] = Double.parseDouble(st1[i]);
  30.             }
  31.             String s2 = cin.nextLine();
  32.             String st2[] = s2.trim().split("\\s+");
  33.             int amount2 = st2.length;
  34.             double arr2[] = new double[amount2];
  35.             for(int i = 0; i < amount2; i++){
  36.                 arr2[i] = Double.parseDouble(st2[i]);
  37.             }            
  38.             double kc = 0, tvh = 0;
  39.             for(int i = 0; i < amount1; i++){
  40.                 kc = kc + ((arr1[i]-arr2[i])*(arr1[i]-arr2[i]));
  41.                 tvh = tvh + (arr1[i] * arr2[i]);
  42.             }
  43.             kc = Math.sqrt(kc);
  44.             long res = (long)tvh;
  45.             System.out.println(String.format("%.2f %d", kc, res));
  46.         }
  47.        
  48.     }
  49.    
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement