Advertisement
Egonau

Untitled

Jan 15th, 2021
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  1. using System;
  2.  
  3. namespace NewLesson1
  4. {
  5.     class Program
  6.     {
  7.         struct Point
  8.         {
  9.            public int x;
  10.            public int y;
  11.             public Point(int x, int y)
  12.             {
  13.                 this.x = x;
  14.                 this.y = y;
  15.             }
  16.             public override string ToString()
  17.             {
  18.                 return $"{x} {y}";
  19.             }
  20.             public static void sort(Point[] points)
  21.             {
  22.                Point b;
  23.                 for (int j = 0; j < points.Length - 1; ++j)
  24.                 {
  25.                     for (int i = 1; i < points.Length; ++i)
  26.                     {
  27.                         if (points[i].Equals( points[i] + points[i - 1])){
  28.                             b = points[i - 1];
  29.                             points[i - 1] = points[i];
  30.                             points[i] = b;
  31.                         }
  32.                     }
  33.                 }
  34.             }
  35.             public static Point operator*(Point coords ,int num)
  36.             {
  37.                 return new Point(coords.x * num, coords.y * num);
  38.             }
  39.             public static Point operator *(int num, Point coords)
  40.             {
  41.                 return new Point(coords.x * num, coords.y * num);
  42.             }
  43.             public static Point operator+(Point left, Point right) //Определяю наибольший из пары Pointов. Перегрузил +, так как с < и > нужно перегружать оба знака обязательно.
  44.             {
  45.                 if (left.x == right.x)
  46.                 {
  47.                     if (left.y > right.y) return new Point(left.x, left.y);
  48.                     else return new Point(right.x, right.y);
  49.                 }
  50.                 else
  51.                 {
  52.                     if (left.x > right.x) return new Point(left.x, left.y);
  53.                     else return new Point(right.x, right.y);
  54.                 }
  55.             }
  56.         }
  57.         static void Main(string[] args)
  58.         {
  59.             Point[] points = new Point[3];
  60.             points[0] = new Point(2, 4);
  61.             points[1] = new Point(2, 8);
  62.             points[2] = new Point(3, 2);
  63.             Point.sort(points);
  64.             int num = 3;
  65.             Point p = new Point(5, 6);
  66.             for (int i = 0; i < points.Length; ++i)
  67.             {
  68.                 Console.WriteLine(points[i]);
  69.             }
  70.             Console.WriteLine(num * p);
  71.             Console.WriteLine(p*num);
  72.         }
  73.     }
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement