Advertisement
ilyakanyshev

Untitled

Dec 4th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. class vector{
  7. public:
  8. float x, y;
  9. void input() {
  10. cin >> this->x >> this->y;
  11. }
  12. float len() {
  13. return sqrt(this->x*this->x + this->y*this->y);
  14. }
  15. vector operator+(vector tmp) {
  16. float x = this->x + tmp.x;
  17. float y = this->y + tmp.y;
  18. if (x >= 7)
  19. x -= 7;
  20. if (y >= 7)
  21. y -= 7;
  22. vector tmp_;
  23. tmp_.x = x; tmp_.y = y;
  24. return tmp_;
  25. }
  26. vector operator-(vector tmp) {
  27. float x = this->x - tmp.x;
  28. float y = this->y - tmp.y;
  29. if (x < 0)
  30. x += 7;
  31. if (y < 0)
  32. y += 7;
  33. vector tmp_;
  34. tmp_.x = x; tmp_.y = y;
  35. return tmp_;
  36. }
  37. int operator--(int n) {
  38. this->x--;
  39. this->y--;
  40. }
  41. int operator++(int n) {
  42. this->x++;
  43. this->y++;
  44. }
  45. };
  46. int main()
  47. {
  48. int n = 4;
  49. vector mass[n];
  50. for (int i = 0; i < n; i++)
  51. {
  52. cout << "Enter " << i+1 << " vector coords: ";
  53. mass[i].input();
  54. }
  55. int n1 = 0, n2 = 1, s = 999999;
  56. for (int i = 0; i < n - 1; i++)
  57. for (int j = i + 1; j < n; j++)
  58. {
  59. vector tmp = mass[i] + mass[j];
  60. if (tmp.len()/2 > s)
  61. {
  62. n1 = i;
  63. n2 = j;
  64. s = tmp.len()/2;
  65. }
  66. }
  67. cout << "Index of elements min sr znachenien: " << n1 << " " << n2 << endl;
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement