Ssup fellow coders
I just started my journey with spoj and I keep encoutering runtime error.
I tried to do the palindrome task. Here is my code (c#)
using System;
using System.Collections.Generic;
namespace Testowanie
{
class Program
{
public static string Reverse(string s)
{
char[] charArray = s.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
public static bool checkStrings(string a, string b)
{
if (a.Length != b.Length)
return false;
for(int i = 0; i<a.Length/2; i++)
{
if (a[i] != b[i])
return false;
}
return true;
}
static void Main(string[] args)
{
int t = Convert.ToInt32(Console.ReadLine());
List<double> lista = new List<double>();
for (int i = 0; i < t; i++)
{
double nowy = Convert.ToDouble(Console.ReadLine());
lista.Add(nowy);
}
foreach(var i in lista)
{
double zwiekszona = i + 1;
string liczba = zwiekszona.ToString();
string liczbaOdwrotna = Reverse(liczba);
while (!checkStrings(liczba, liczbaOdwrotna))
{
zwiekszona++;
liczba = zwiekszona.ToString();
liczbaOdwrotna = Reverse(liczba);
}
Console.WriteLine(liczba);
}
}
}
}
Whenever I try to submit this badboy I get a runtime error (NZEC). Sb please tell me why is this occuring?
Here is a link to the task : https://www.spoj.com/problems/PALIN/3
created
last reply
- 3
replies
- 527
views
- 2
users
- 1
like
- 1
link