svetlozar_kirkov

Magic Dates

Oct 6th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. class ConsoleTests
  5. {
  6.     static void Main()
  7.     {
  8.         int startYear = int.Parse(Console.ReadLine());
  9.         int endYear = int.Parse(Console.ReadLine());
  10.         int magicWeight = int.Parse(Console.ReadLine());
  11.         DateTime startDay = new DateTime(startYear, 01, 01);
  12.         DateTime endDay = new DateTime(endYear,12,31);
  13.         int count = 0;
  14.  
  15.         for (DateTime i = startDay; i <= endDay; i=i.AddDays(1) )
  16.         {
  17.             int tempWeight = 0;
  18.             string currentDate = i.ToString("ddMMyyyy",
  19.                          CultureInfo.InvariantCulture);
  20.             int[] dateArray = new int[8];
  21.             for (int j = 0; j < dateArray.Length; j++)
  22.             {
  23.                 dateArray[j] = Convert.ToInt32(currentDate[j].ToString());
  24.             }
  25.             for (int k = 0; k < dateArray.Length; k++)
  26.             {
  27.                 for (int m = k+1; m < dateArray.Length; m++)
  28.                 {
  29.                     tempWeight += dateArray[k]*dateArray[m];
  30.                 }
  31.             }
  32.             if (tempWeight == magicWeight)
  33.             {
  34.                 Console.WriteLine(i.ToString("dd-MM-yyyy"));
  35.                 count++;
  36.             }
  37.         }
  38.  
  39.         if (count==0)
  40.         {
  41.             Console.WriteLine("No");
  42.         }
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment