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;
- namespace ConsoleApp9
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] weapons = new string[0];
- string[] bag = new string[0];
- bool run = true;
- string vvod = " ";
- string[] command = new string[0];
- Console.WriteLine("Введите ADD перед названием оружия, чтобы добавить его в сумку или DEL чтобы удалить из сумки" +
- "\nВведите LIST чтобы просмотреть содержимое сумки");
- while (run)
- {
- vvod = Console.ReadLine();
- command = vvod.Split(' ');
- switch (command[0].ToLower())
- {
- case "add":
- AddWeapon(ref command, ref weapons);
- break;
- case "del":
- DelWeapons(ref command,ref weapons);
- break;
- case "list":
- ListBag(ref bag, ref weapons);
- break;
- case "exit":
- run = false;
- break;
- default:
- Console.WriteLine("Невозможно выполнить операцию! Для выхода наберите EXIT.");
- break;
- }
- }
- Console.ReadKey();
- }
- public static string [] AddWeapon(ref string [] command, ref string [] weapons)
- {
- int contain = -1;
- for (int j = 0; j < weapons.Length; j++)
- {
- if (weapons[j].ToLower() == command[1].ToLower())
- {
- contain = j;
- }
- }
- if (contain == -1)
- {
- string[] tempweapons = new string[weapons.Length + 1];
- for (int i = 0; i < weapons.Length; i++)
- {
- tempweapons[i] = weapons[i];
- }
- tempweapons[weapons.Length] = command[1];
- weapons = tempweapons;
- Console.WriteLine("Оружие " + weapons[weapons.Length-1] + " добавлено в сумку!");
- }
- else
- {
- Console.WriteLine("Такоe оружие уже есть в сумке!");
- }
- return weapons;
- }
- public static string[] DelWeapons(ref string[] command, ref string[] weapons)
- {
- int contain = -1;
- for (int j = 0; j < weapons.Length; j++)
- {
- if (weapons[j].ToLower() == command[1].ToLower())
- {
- contain = j;
- }
- }
- if (contain == -1)
- {
- Console.WriteLine("Такого оружия нет в сумке!");
- }
- else
- {
- Console.WriteLine("Оружие " + weapons[contain] + " удалено из сумки!");
- for (int i = contain; i < weapons.Length - 1; i++)
- {
- weapons[i] = weapons[i + 1];
- }
- string[] tempweapons = new string[weapons.Length - 1];
- for (int i = 0; i < tempweapons.Length; i++)
- {
- tempweapons[i] = weapons[i];
- }
- weapons = tempweapons;
- }
- return weapons;
- }
- public static string[] ListBag(ref string[] bag, ref string[] weapons)
- {
- Console.WriteLine("В сумке лежит оружие:");
- bag = weapons;
- for (int i = 0; i < bag.Length; i++)
- {
- Console.WriteLine(i + 1 + "." + bag[i]);
- }
- return bag;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement