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;
- class Program
- {
- static void Main(string[] args)
- {
- string[] massive = new string[0];
- string vvod;
- bool run = true;
- Random rnd = new Random();
- while (run)
- {
- Console.Write("Введите слово, комманду SHUFFLE для перемешивания или EXIT для выхода:");
- vvod = Console.ReadLine();
- if (vvod.ToLower() == "exit")
- {
- run = false;
- }
- if (vvod.ToLower() == "shuffle")
- {
- Shuffle(ref rnd,ref vvod,ref massive);
- Console.WriteLine("Элементы в массиве перемешаны!");
- for (int i = 0; i<massive.Length; i++)
- {
- Console.WriteLine(massive[i]);
- }
- }
- else
- {
- Add(ref vvod,ref massive);
- Console.WriteLine("В массиве теперь есть следующие элементы:");
- for (int i = 0; i < massive.Length; i++)
- {
- Console.WriteLine(massive[i]);
- }
- }
- }
- }
- public static string[] Add(ref string vvod,ref string[] massive)
- {
- string[] tempMassive = new string[massive.Length + 1];
- for (int i = 0; i < massive.Length; i++)
- {
- tempMassive[i] = massive[i];
- }
- tempMassive[massive.Length] = vvod;
- massive = tempMassive;
- return massive;
- }
- public static string[] Shuffle(ref System.Random rnd,ref string vvod,ref string[] massive)
- {
- string[] tempMassive = new string[massive.Length];
- tempMassive = massive;
- for (int i = 0; i< massive.Length;i++)
- {
- string tempMem = tempMassive[i];
- int seed = rnd.Next(0, massive.Length);
- tempMassive[i] = massive[seed];
- massive[seed] = tempMem;
- }
- tempMassive = massive;
- return massive;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement