Jolly Jumpers
A sequence is "Jolly Jumper" if the absolute value of the differences between values exists in the provided string.
Entrada: una cadena con números
Salida: true/ false
Prueba:
1432 : true
5142 : false
This is the code
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace JollyJumpers
{
class MainClass
{
public static void Main(string[] args)
{
try
{
StreamReader inFile = new StreamReader("input.in");
StreamWriter outFile = new StreamWriter("output.out");
MatchCollection matches = Regex.Matches(inFile.ReadLine(), @"\d+");
int quantity;
int[] numbers;
int[] results;
while (!inFile.EndOfStream)
{
quantity = Convert.ToInt32(matches[0].ToString());
numbers = new int[quantity];
results = new int[quantity - 1];
bool flag = true;
for (int i = 0; i < quantity; i++)
numbers[i] = Convert.ToInt32(matches[i + 1].ToString());
for (int i = 0; i < quantity - 1; i++)
results[i] = Math.Abs(numbers[i] - numbers[i + 1]);
for (int i = 0; i < quantity - 2; i++)
{
if (Math.Abs(results[i] - results[i + 1]) != 1)
{
flag = false;
break;
}
}
if (flag)
outFile.WriteLine("Jolly");
else
outFile.WriteLine("Not Jolly");
matches = Regex.Matches(inFile.ReadLine(), @"\d+");
numbers = null;
results = null;
}
Console.Write("Finishing the Program");
Console.Read();
inFile.Close();
outFile.Close();
}
catch (System.IO.FileNotFoundException)
{
Console.WriteLine("File does not exist");
Console.Read();
}
catch
{
Console.WriteLine("Something Unexpected happened");
Console.Read();
}
}
}
}
When the code is executed, the following message appears on the console
File does not exist
What is the problem?