Kolimnared

MagicWeight

Oct 17th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Globalization;
  4.  
  5. class MagicDates
  6. {
  7. private static int GetWeigth(DateTime date) {
  8. string str = date.ToString("ddMMyyyy");
  9. int len = str.Length;
  10. int[] arr = new int[len];
  11. char[] cArr = str.ToCharArray();
  12.  
  13. for (int i = 0; i < len; i++){
  14. arr[i] = cArr[i] - '0';
  15. }
  16.  
  17. int weigth = 0;
  18. for (int i = 0; i < len - 1; i++) {
  19. if (arr[i] != 0) {
  20. for (int j = i + 1; j < len; j++) {
  21. weigth += arr[i] * arr[j];
  22. }
  23. }
  24. }
  25.  
  26. return weigth;
  27. }
  28.  
  29. static void Main(string[] args)
  30. {
  31. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
  32.  
  33. int startYear = int.Parse(Console.ReadLine());
  34. int endYear = int.Parse(Console.ReadLine());
  35. int weigth = int.Parse(Console.ReadLine());
  36.  
  37. DateTime startDate = new DateTime(startYear, 1, 1);
  38. DateTime endDate = new DateTime(endYear, 12, 31);
  39.  
  40. bool success = false;
  41. for (; startDate <= endDate; startDate = startDate.AddDays(1)) {
  42. if (GetWeigth(startDate) == weigth) {
  43. Console.WriteLine(startDate.ToString("dd-MM-yyyy"));
  44. success = true;
  45. }
  46. }
  47.  
  48. if(!success)
  49. Console.WriteLine("No");
  50. }
  51. }
Add Comment
Please, Sign In to add comment