using System; public class Test { public static void Main() { //init and print Console.WriteLine("Init"); SpecialArray<int> test = new SpecialArray<int>(0, 10); test.Print(); //set all and print Console.WriteLine("Set All to 12"); test.SetAll(12); test.Print(); //set some values and print Console.WriteLine("Set some values"); test.Set(4, 3); test.Set(6, 2); test.Set(0, 0); test.Print(); //set all again and print Console.WriteLine("Set all to 14"); test.SetAll(14); test.Print(); //set some values again and print Console.WriteLine("Set some values"); test.Set(4, 4); test.Set(6, 5); test.Set(0, 6); test.Print(); //set all again and print Console.WriteLine("Set all to 16"); test.SetAll(16); test.Print(); //printing tests the Get method works Console.ReadLine(); } } public class SpecialValue<T> { public bool mode = true; public bool haslocal = false; public T local; } public class SpecialArray<T> { SpecialValue<T>[] array; bool mode; int size; T globalTrue; T globalFalse; public SpecialArray(T globalValue, int size) { this.size = size; mode = true; globalTrue = globalValue; array = new SpecialValue<T>[size]; for (int i = 0; i < size; i++) array[i] = new SpecialValue<T>(); } public T Get(int i) { SpecialValue<T> val = array[i]; if (val.mode == mode) { if (val.haslocal) return val.local; else return val.mode ? globalTrue : globalFalse; } else { val.mode = mode; val.haslocal = false; return val.mode ? globalTrue : globalFalse; } } public void Set(int i, T value) { SpecialValue<T> val = array[i]; val.haslocal = true; val.local = value; } public void SetAll(T value) { mode = !mode; if (mode) globalTrue = value; else globalFalse = value; } public void Print() { for (int i = 0; i < size; i++) Console.Write(Get(i).ToString() + ", "); //meh good enough Console.WriteLine(); } }
Standard input is empty
Init 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Set All to 12 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, Set some values 0, 12, 12, 12, 3, 12, 2, 12, 12, 12, Set all to 14 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, Set some values 6, 14, 14, 14, 4, 14, 5, 14, 14, 14, Set all to 16 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,