Advertisement
Guest User

Blackone

a guest
Nov 10th, 2009
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. // Main.cs created with MonoDevelop
  2. // Jeffrey
  3. //
  4. // To change standard headers go to Edit->Preferences->Coding->Standard Headers
  5. //
  6. using System;
  7. using System.IO;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10.  
  11. namespace JollyJumpers
  12. {
  13.     class MainClass
  14.     {
  15.         public static void Main(string[] args)
  16.         {
  17.             try
  18.             {
  19.                 StreamReader inFile = new StreamReader("input.in");
  20.                 StreamWriter outFile = new StreamWriter("output.out");
  21.                 MatchCollection matches = Regex.Matches(inFile.ReadLine(), @"\d+");
  22.                 int quantity;
  23.                 int[] numbers;
  24.                 int[] results;
  25.                
  26.                 while(!inFile.EndOfStream)
  27.                 {
  28.                     quantity = Convert.ToInt32(matches[0].ToString());
  29.                     numbers = new int[quantity];
  30.                     results = new int[quantity-1];
  31.                     bool flag = true;
  32.                    
  33.                     for(int i=0; i < quantity; i++)
  34.                         numbers[i] = Convert.ToInt32(matches[i+1].ToString());
  35.  
  36.                     for(int i=0; i < quantity-1; i++)
  37.                         results[i] = Math.Abs(numbers[i] - numbers[i+1]);
  38.                    
  39.                     for(int i=0; i < quantity-2; i++)
  40.                     {
  41.                         if(Math.Abs(results[i] - results[i+1]) != 1)
  42.                         {
  43.                             flag = false;
  44.                             break;
  45.                         }
  46.                     }
  47.                    
  48.                     if(flag)
  49.                         outFile.WriteLine("Jolly");
  50.                     else
  51.                         outFile.WriteLine("Not Jolly");
  52.                    
  53.                     matches = Regex.Matches(inFile.ReadLine(), @"\d+");
  54.                    
  55.                     numbers = null;
  56.                     results = null;
  57.                 }
  58.                 Console.Write("Finishing the Program");
  59.                 Console.Read();
  60.                 inFile.Close();
  61.                 outFile.Close();
  62.                
  63.             }
  64.             catch(System.IO.FileNotFoundException)
  65.             {
  66.                 Console.WriteLine("File does not exist");
  67.                 Console.Read();
  68.             }
  69.             catch
  70.             {
  71.                 Console.WriteLine("Something Unexpected happened");
  72.                 Console.Read();
  73.             }
  74.                
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement