Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/04/2012, 16:44
Avatar de newmesis
newmesis
 
Fecha de Ingreso: octubre-2010
Ubicación: Chillán, Chile, Chile
Mensajes: 42
Antigüedad: 13 años, 7 meses
Puntos: 0
identificar romano si es par o impar

Hola amigos mi profesor me paso este codigo


Código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace STLibraries.Roman
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                do
                {
                    string roman, unit;

                    Console.Clear();
                    Console.Write("\nIngrese un número romano entre 1 y 3999: ");

                    roman = Console.ReadLine();

                    if (RomanIsPair(roman.ToUpper(), out unit))
                    {
                        Console.WriteLine("-> El número romano: {0}, es par.", roman);
                    }
                    else
                    {
                        Console.WriteLine("-> El número romano: {0}, es impar.", roman);
                    }

                    Console.Write("\nPresione 'Esc' para salir o una tecla para continuar...");

                } while (ConsoleKey.Escape != Console.ReadKey().Key);
            }
            catch (Exception e)
            {
                Console.WriteLine("Se ha producido el siguiente error:");
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }

        }

        /// <summary>
        /// unknown function
        /// </summary>
        /// <param name="roman"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        static bool RomanIsPair(string roman, out string unit)
        {
            bool isPair;
            int @long;
            char[] cRoman;

            isPair = false;
            roman = "@" + roman;
            @long = roman.Length;
            unit = string.Empty;
            cRoman = roman.ToCharArray();

            for (int i = 0; i < @long; i++)
            {
                int j = (@long - 1) - i;

                if (cRoman[j] != '@')
                {
                    if ((cRoman[j].ToString() == "I") ||
                            (cRoman[j].ToString() == "V") ||
                                (cRoman[j - 1].ToString() + cRoman[j].ToString() == "IX"))
                    {
                        unit = cRoman[j].ToString() + unit;
                    }
                    else { break; }
                }
            }

            return isPair;
        }

    }
}


el código debe identificar


se ingresar numero en romano

ejemplo

V que es igual a 5 el programa deve identificar si ese es numero par o impar

nesesito solo una referencia para poder ejecutar y arreglarlo
gracias