zh_stoqnov

Magic Dates

Oct 27th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Magic_Dates
  8. {
  9. class MagicDates
  10. {
  11. static void Main(string[] args)
  12. {
  13. int startYear = int.Parse(Console.ReadLine());
  14. int endYear = int.Parse(Console.ReadLine());
  15. int magicWeight = int.Parse(Console.ReadLine());
  16.  
  17. DateTime start = new DateTime(startYear, 1, 1);
  18. DateTime end = new DateTime(endYear, 12, 31);
  19. int count = 0;
  20. for (DateTime d = start; d <= end; d = d.AddDays(1))
  21. {
  22. int d1 = d.Day / 10;
  23. int d2 = d.Day % 10;
  24. int d3 = d.Month / 10;
  25. int d4 = d.Month % 10;
  26. int d5 = (d.Year / 1000) % 10;
  27. int d6 = (d.Year / 100) % 10;
  28. int d7 = (d.Year / 10) % 10;
  29. int d8 = (d.Year / 1) % 10;
  30. int[] digits = { d1, d2, d3, d4, d5, d6, d7, d8 };
  31. int weight = 0;
  32. for(int i = 0; i < digits.Length; i++)
  33. {
  34. for(int k = i + 1; k < digits.Length; k++)
  35. {
  36. weight = weight + (digits[i] * digits[k]);
  37. }
  38. }
  39. if (weight == magicWeight)
  40. {
  41. Console.WriteLine("{0:d2}-{1:d2}-{2:d2}", d.Day, d.Month, d.Year);
  42. count++;
  43. }
  44. }
  45. if (count == 0)
  46. {
  47. Console.WriteLine("No");
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment