Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- using System.IO;
- class MainClass
- {
- class Vector
- {
- int[] IntArray;
- public int Size
- {
- get;
- }
- public int Scalar
- {
- set
- {
- for (int i = 0; i < IntArray.Length; i++)
- {
- IntArray[i] *= value;
- }
- }
- }
- public int this[int index]
- {
- get { return IntArray[index]; }
- }
- public Vector(int size)
- {
- IntArray = new int[size];
- Size = size;
- }
- public Vector() { IntArray = new int[0]; }
- public void Input()
- {
- string[] line = Console.ReadLine().Split();
- for (int i = 0; i < IntArray.Length; ++i)
- {
- IntArray[i] = int.Parse(line[i]);
- }
- }
- public void Show()
- {
- Console.Write("Vector : ");
- foreach (var item in IntArray)
- Console.Write(item + " ");
- Console.WriteLine();
- }
- public void Sort()
- {
- Array.Sort(IntArray);
- }
- public static Vector operator --(Vector p)
- {
- for (int i = 0; i < p.Size; ++i)
- p.IntArray[i]--;
- return p;
- }
- public static Vector operator ++(Vector p)
- {
- for (int i = 0; i < p.Size; ++i)
- p.IntArray[i]++;
- return p;
- }
- public static bool operator !(Vector a)//перегрузка оператора '!'
- {
- for (int i = 1; i < a.IntArray.Length; ++i)
- if (a.IntArray[i] < a.IntArray[i - 1])
- return false;
- return true;
- }
- public static Vector operator *(Vector a, int scalar)//перегрузка оператора '*'
- {
- a.Scalar = scalar;
- return a;
- }
- public static implicit operator Vector(int [] obj)//явное приведение к MyString
- {
- Vector res = new Vector(obj.Length);
- for (int i = 0; i < obj.Length; ++i)
- res.IntArray[i] = obj[i];
- return res;
- }
- public static implicit operator int [](Vector vec)//явное приведение к string
- {
- int [] res = new int[vec.Size];
- for (int i = 0; i < vec.Size; ++i)
- res[i] = vec.IntArray[i];
- return res;
- //Я тут кое что изменил,если не работает отпиши
- }
- }
- public static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Vector a = new Vector(n);
- a.Input();
- a.Show();
- Console.WriteLine("size = " + a.Size);
- int idx = 3;
- Console.WriteLine($"{idx}-th element = " + a[idx]);
- a--;
- a.Show();
- a = a * 3;
- a.Show();
- int[] array = a;
- Console.Write("convert to array : ");
- for (int i = 0; i < array.Length; ++i)
- Console.Write(array[i] + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement