Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- public static class Program
- {
- public static void Main()
- {
- var journal = Console.ReadLine().Split(new []{',',' '},StringSplitOptions.RemoveEmptyEntries).ToArray();
- var exists = false;
- var index = -1;
- while(true)
- {
- var input = Console.ReadLine();
- if(input == "exit")
- {
- break;
- }
- var commands = input.Split(" - ");
- string command = commands[0];
- if(command == "Collect")
- {
- string item = commands[1];
- if(Exists(exists, journal, item) == false)
- {
- var newJournal = new string[journal.Length + 1];
- for(int i=0;i<journal.Length;i++)
- {
- newJournal[i]=journal[i];
- }
- newJournal[newJournal.Length-1] = item;
- journal = newJournal;
- }
- }
- if(command == "Drop")
- {
- string item = commands[1];
- if (Exists(exists, journal, item))
- {
- journal = RemoveAt(journal, Index(exists, journal, item, index));
- //string[] newJournal = new string[journal.Length - 1];
- //if( Index(exists,journal, item, index) > 0 )
- //{
- // for(int i = 0;i<Index(exists, journal, item, index);i++)
- // {
- // newJournal[i] = journal[i];
- // }
- //}
- //if( Index(exists, journal, item, index) < journal.Length - 1 )
- //{
- // for(int i=Index(exists, journal, item, index);i<journal.Length-Index(exists, journal,item, index)-1;i++)
- // {
- // newJournal[Index(exists, journal, item, index)] = journal[Index(exists, journal, item, index)+1];
- // }
- //}
- //
- // journal = newJournal;
- }
- }
- if(command == "Combine Items")
- {
- var items = commands[1].Split(':');
- var oldItem = items[0];
- var newItem = items[1];
- if(Exists(exists, journal, oldItem))
- {
- var newJournal = new string[journal.Length+1];
- }
- }
- if(command=="Renew")
- {
- string item = commands[1];
- }
- }
- for(int i=0;i<journal.Length-1;i++)
- {
- Console.Write(journal[i] + ", ");
- }
- Console.Write(journal[journal.Length-1]);
- Console.WriteLine(" ");
- }
- public static bool Exists(bool exists, string[] journal, string item)
- {
- for(int i=0;i<journal.Length;i++)
- {
- if(item == journal[i])
- {
- exists = true;
- }
- }
- return exists;
- }
- public static int Index(bool exists, string[] journal, string item, int index)
- {
- for(int i=0;i<journal.Length;i++)
- {
- if(item == journal[i])
- {
- exists = true;
- index = i;
- }
- }
- return index;
- }
- //public static T[] RemoveAt<T>(this T[] journal, int index)
- //{
- // T[] dest = new T[journal.Length - 1];
- // if( index > 0 )
- // Array.Copy(journal, 0, dest, 0, index);
- // if( index < journal.Length - 1 )
- // Array.Copy(journal, index + 1, dest, index, journal.Length - index - 1);
- // return dest;
- //}
- public static string[] RemoveAt(string[] journal, int index)
- {
- string[] dest = new string[journal.Length - 1];
- if( index > 0 )
- Array.Copy(journal, 0, dest, 0, index);
- if( index < journal.Length - 1 )
- Array.Copy(journal, index + 1, dest, index, journal.Length - index - 1);
- return dest;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment