Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Example
- {
- class Program
- {
- const int MAX_N = 128;
- static void add(int k, int x, ref int n, ref int[] a)
- {
- if (k >= 0 && k < n && n < MAX_N)
- {
- for (int i = n; i > k; --i)
- a[i] = a[i - 1];
- a[k] = x;
- ++n;
- }
- }
- static void erase(int k, ref int n, ref int[] a)
- {
- if (n > 0 && k >= 0 && k < n)
- {
- for (int i = k; i < n - 1; ++i)
- a[i] = a[i + 1];
- --n;
- }
- }
- static void print(int n, int[] a)
- {
- for (int i = 0; i < n; ++i)
- Console.Write("{0} ", a[i]);
- Console.Write("\n");
- }
- static void Main()
- {
- Console.Write("n = ");
- int n = int.Parse(Console.ReadLine());
- int[] a = new int[MAX_N];
- Random num = new Random();
- for (int i = 0; i < n; ++i)
- a[i] = num.Next(100);
- print(n, a);
- string state = "";
- while (state != "stop")
- {
- state = Console.ReadLine();
- string[] s = state.Split(" ");
- if (s[0] == "add") add(int.Parse(s[1]), int.Parse(s[2]), ref n, ref a);
- else if (s[0] == "erase") erase(int.Parse(s[1]), ref n, ref a);
- print(n, a);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement