I can invert two numbers of an array with the array.reverse
but, in this case, I have declared a String
that you enter by the input method and that this is transformed into an array with the Split
method separated by ','
.
In the chain these combinations can exist: 1,12,2,23,3,34,4,14
.
What I need is that if you enter by keyboard 21
you invert it to 12
, as with 32
, that is reversed to 23
etc.
My question is the following to see if I explain myself well. I have stored in the array numbers between 1 and 4 combined example: 12,32,41,24). Leaving aside that there are combinations that can not exist due to the requirements of my exercise, I need to look inside the positions of the array if the number is ordered from least to greatest and if it is not changing it. Currently my program does not solve this problem just put me left right up down etc when I insert a number but it has to be well ordered (from lowest to highest), if I do not order it shows me the number without more, not the enum to which refers. I think I would have to first look at the index [i] of the array and buy the number that is inside it but being a two-digit number you will not buy the first character with the second one.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ejercicio3
{
class Program
{
enum direcion { arriba = 1, abajo = 3, derecha = 2, izquieda = 4,
abajoDerecha=23, abajoIzquierda=34,arribaDerecha=12,arribaIzquieda=14,
prohibido };
static void Main(string[] args)
{
string num = "";
Console.WriteLine("Escribe la direcion que desees tomar");
num = Console.ReadLine();
string[] array = num.Split(',');
for (int i = 0; i < array.Length; i++)
{
if (array[i].Length==2)
{
var a=int.Parse(array[i].Substring(0, 1));
var b=int.Parse(array[i].Substring(1,2));
{
if (a < b)
{
array[i].Reverse;
}
}
}
Console.WriteLine("{0}", (direcion)int.Parse(array[i]));
}
}
}
}