Created
April 22, 2013 22:52
-
-
Save hminaya/5439286 to your computer and use it in GitHub Desktop.
Ejemplo en C# (para correr con mono) de como sacar un palindromo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Diagnostics; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace palindrome | |
{ | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
var reloj = new Stopwatch(); | |
reloj.Start(); | |
var cantidadPalindromos = 0; | |
var archivo = File.ReadAllLines("seed.txt"); | |
Console.WriteLine("Archivo cargado en memoria {0}", reloj.Elapsed); | |
//Lectura del archivo | |
foreach (var linea in archivo) | |
{ | |
int num1 = Convert.ToInt32(linea.Split(' ')[0]); | |
int num2 = Convert.ToInt32(linea.Split(' ')[1]); | |
for (int i = num1; i < num2; i++) { | |
String b = i.ToString(); | |
if (b.SequenceEqual(b.Reverse())) { | |
cantidadPalindromos++; | |
} | |
} | |
} | |
reloj.Stop(); | |
Console.WriteLine("{0} palíndromos encontrados. {1}", cantidadPalindromos, reloj.Elapsed); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment