fork(4) download
  1. #include <iostream>
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. struct Vector2
  8. {
  9. double x, y;
  10. };
  11.  
  12. double angle(Vector2 a, Vector2 b) // oblicz kąt pomiędzy wektorami
  13. {
  14. return acos ( (a.x * b.x + a.y * b.y) / ( sqrt( pow(a.x, 2) + pow(a.y, 2) ) * sqrt( pow(b.x, 2) + pow(b.y, 2) )) );;
  15. }
  16.  
  17. double deg(double rad) // Zamień radiany na stopnie
  18. {
  19. return rad/M_PI*180;
  20. }
  21.  
  22. int main()
  23. {
  24. Vector2 a, b;
  25. while(cin>>a.x>>a.y>>b.x>>b.y)
  26. {
  27.  
  28. cout<<deg(angle(a, b))<<endl; // Wypisz kąt pomiędzy wektorami
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0.02s 2860KB
stdin
10 10 -1 1
1 0 1 -1
1 0 -1 0
10 10 -10 -10
3 4 -1 6

stdout
90
45
180
180
46.3322