Advertisement
Infiniti_Inter

17-V (S)

Dec 9th, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7. using System.IO;
  8.  
  9.  
  10. class MainClass
  11. {
  12.  
  13.     class Vector
  14.     {
  15.         int[] IntArray;
  16.  
  17.         public int Size
  18.         {
  19.             get;
  20.         }
  21.  
  22.         public int Scalar
  23.         {
  24.             set
  25.             {
  26.                 for (int i = 0; i < IntArray.Length; i++)
  27.                 {
  28.                     IntArray[i] *= value;
  29.                 }
  30.             }
  31.         }
  32.         public int this[int index]
  33.         {
  34.             get { return IntArray[index]; }
  35.         }
  36.  
  37.         public Vector(int size)
  38.         {
  39.             IntArray = new int[size];
  40.             Size = size;
  41.         }
  42.         public Vector() { IntArray = new int[0]; }
  43.  
  44.         public void Input()
  45.         {
  46.             string[] line = Console.ReadLine().Split();
  47.             for (int i = 0; i < IntArray.Length; ++i)
  48.             {
  49.                 IntArray[i] = int.Parse(line[i]);
  50.             }
  51.         }
  52.  
  53.         public void Show()
  54.         {
  55.             Console.Write("Vector : ");
  56.             foreach (var item in IntArray)
  57.                 Console.Write(item + " ");
  58.             Console.WriteLine();
  59.         }
  60.         public void Sort()
  61.         {
  62.             Array.Sort(IntArray);
  63.         }
  64.  
  65.  
  66.         public static Vector operator --(Vector p)
  67.         {
  68.             for (int i = 0; i < p.Size; ++i)
  69.                 p.IntArray[i]--;
  70.             return p;
  71.         }
  72.         public static Vector operator ++(Vector p)
  73.         {
  74.             for (int i = 0; i < p.Size; ++i)
  75.                 p.IntArray[i]++;
  76.             return p;
  77.         }
  78.  
  79.         public static bool operator !(Vector a)//перегрузка оператора '!'
  80.         {
  81.             for (int i = 1; i < a.IntArray.Length; ++i)
  82.                 if (a.IntArray[i] < a.IntArray[i - 1])
  83.                     return false;
  84.             return true;
  85.         }
  86.         public static Vector operator *(Vector a, int scalar)//перегрузка оператора '*'
  87.         {
  88.             a.Scalar = scalar;
  89.             return a;
  90.         }
  91.  
  92.  
  93.         public static implicit operator Vector(int [] obj)//явное приведение к MyString
  94.         {
  95.             Vector res = new Vector(obj.Length);
  96.             for (int i = 0; i < obj.Length; ++i)
  97.                 res.IntArray[i] = obj[i];
  98.             return res;
  99.         }
  100.  
  101.         public static implicit operator int [](Vector vec)//явное приведение к string
  102.         {
  103.             int [] res = new int[vec.Size];
  104.             for (int i = 0; i < vec.Size; ++i)
  105.                 res[i] = vec.IntArray[i];
  106.             return res;
  107. //Я тут кое что изменил,если не работает отпиши
  108.         }
  109.  
  110.     }
  111.  
  112.  
  113.     public static void Main(string[] args)
  114.     {
  115.         int n = int.Parse(Console.ReadLine());
  116.         Vector a = new Vector(n);
  117.         a.Input();
  118.         a.Show();
  119.         Console.WriteLine("size = " + a.Size);
  120.         int idx = 3;
  121.        
  122.         Console.WriteLine($"{idx}-th element = " + a[idx]);
  123.         a--;
  124.         a.Show();
  125.         a = a * 3;
  126.         a.Show();
  127.  
  128.         int[] array = a;
  129.         Console.Write("convert to array : ");
  130.         for (int i = 0; i < array.Length; ++i)
  131.             Console.Write(array[i] + " ");
  132.  
  133.  
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement