Advertisement
Guest User

MagicDates

a guest
Aug 10th, 2014
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using System;
  2.  
  3. class MagicDates
  4. {
  5. static void Main()
  6. {
  7. int startyear = int.Parse(Console.ReadLine());
  8. int endyear = int.Parse(Console.ReadLine());
  9. int magic = int.Parse(Console.ReadLine());
  10. bool hasAnswer = false;
  11. int tempmagic ;
  12. string date;
  13.  
  14. for (int year = startyear; year <= endyear; year++)
  15. {
  16. for (int mount = 1; mount <= 12; mount++)
  17. {
  18. for (int day = 1; day <= 31; day++)
  19. {
  20. tempmagic = 0;
  21. if ((!DateTime.IsLeapYear(year) && mount == 2 && day > 28)||
  22. ( DateTime.IsLeapYear(year) && mount == 2 && day > 29)||
  23. (day == 31 && (mount==4 && mount == 6 && mount == 9 && mount == 11)))
  24. {
  25. continue;
  26. }
  27. else
  28. {
  29. date = day.ToString() + mount + year;
  30. for (int i = 0; i < date.Length; i++)
  31. {
  32. int a = int.Parse(date[i].ToString());
  33. for (int j = i+1; j < date.Length; j++)
  34. {
  35. int b = int.Parse(date[j].ToString());
  36. tempmagic += a * b;
  37. }
  38. }
  39. if (tempmagic == magic)
  40. {
  41. DateTime printdate = new DateTime(year, mount , day);
  42. Console.WriteLine(printdate.ToString("dd-MM-yyyy"));
  43. hasAnswer = true;
  44. }
  45. }
  46. }
  47. }
  48. }
  49. if (!hasAnswer)
  50. {
  51. Console.WriteLine("No");
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement