Created
July 1, 2015 15:40
-
-
Save VegaFromLyra/495aa9d05b8f1c5d6703 to your computer and use it in GitHub Desktop.
Palindrome checker
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.Text; | |
namespace PalindromeChecker | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
using(StreamReader sr = new StreamReader("palindrome.in")) | |
{ | |
string num = sr.ReadLine(); | |
int numberOfInputs = Int32.Parse(num); | |
string line; | |
int count = 1; | |
bool isFirstLine = true; | |
while ((line = sr.ReadLine()) != null && | |
(count <= numberOfInputs)) { | |
using (StreamWriter sw = File.AppendText("palindrome.out")) { | |
sw.WriteLine("Case #{0}", count); | |
if (isPalindrome(line)) { | |
sw.WriteLine("yes"); | |
} else { | |
sw.WriteLine("no"); | |
} | |
} | |
count++; | |
} | |
} | |
Console.WriteLine("Done"); | |
} | |
static bool isPalindrome(String s) { | |
if (String.IsNullOrEmpty(s)) { | |
return true; | |
} | |
int start = 0; | |
int end = s.Length - 1; | |
while (start < end) { | |
if (s[start] != s[end]) { | |
return false; | |
} | |
start++; | |
end--; | |
} | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment