예제 #1
0
        public bool EsPalindromo(string palabra)
        {
            bool result = false;

            if (HttpContext.Current.Cache["Palabras"] != null)
            {
                palindromoDic = HttpContext.Current.Cache["Palabras"] as Dictionary <string, bool>;
            }

            if (palindromoDic.ContainsKey(palabra))
            {
                palindromoDic.TryGetValue(palabra, out result);
            }
            else
            {
                BPalindromo buss          = new BPalindromo();
                var         resPalindromo = buss.ValidarPalindromos(new List <string> {
                    palabra
                });
                palindromoDic.Add(palabra, resPalindromo.FirstOrDefault().EsPalindromo);
                result = resPalindromo.FirstOrDefault().EsPalindromo;
            }
            if (HttpContext.Current.Cache["Palabras"] == null)
            {
                HttpContext.Current.Cache.Insert("Palabras", palindromoDic, null, DateTime.Now.AddMinutes(15), TimeSpan.Zero);
            }

            return(result);
        }
예제 #2
0
        static void Main(string[] args)
        {
            List <string> palabras = new List <string>();
            string        palabra  = string.Empty;

            FileInfo file = new FileInfo(@"c:\test.txt");

            if (!file.Exists)
            {
                Console.WriteLine(@"Por favor agregue el archivo test.txt en 'c:\' y ejecute de nuevo la aplicación");
                Console.ReadKey();
                return;
            }

            StreamReader archivo = new StreamReader(file.FullName);

            while ((palabra = archivo.ReadLine()) != null)
            {
                palabras.Add(palabra);
            }

            BPalindromo buss = new BPalindromo();

            var palindromos = buss.ValidarPalindromos(palabras);

            foreach (Palindromo palindromo in palindromos)
            {
                Console.WriteLine($"{palindromo.Palabra}: {palindromo.EsPalindromo}");
            }
            Console.ReadKey();
        }
예제 #3
0
        public bool AgregraPalabra(string palabra)
        {
            if (HttpContext.Current.Cache["Palabras"] != null)
            {
                palindromoDic = HttpContext.Current.Cache["Palabras"] as Dictionary <string, bool>;
            }
            if (palindromoDic.ContainsKey(palabra))
            {
                return(true);
            }
            else
            {
                BPalindromo buss          = new BPalindromo();
                var         resPalindromo = buss.ValidarPalindromos(new List <string> {
                    palabra
                });
                palindromoDic.Add(palabra, resPalindromo.FirstOrDefault().EsPalindromo);
                HttpContext.Current.Cache.Remove("Palabras");
                HttpContext.Current.Cache.Insert("Palabras", palindromoDic, null, DateTime.Now.AddMinutes(15), TimeSpan.Zero);

                return(true);
            }
        }