Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Threading;
- namespace _04.MagicDates
- {
- class Program
- {
- static void Main()
- {
- Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
- int startYear = int.Parse(Console.ReadLine());
- int endYear = int.Parse(Console.ReadLine());
- int magicWeight = int.Parse(Console.ReadLine());
- List<DateTime> dates = new List<DateTime>();
- DateTime startDate = new DateTime(startYear, 1, 1);
- DateTime endDate = new DateTime(endYear, 12, 31);
- int result = 0;
- int mult = 0;
- for (DateTime currentDate = startDate; currentDate <= endDate; currentDate = currentDate.AddDays(1))
- {
- result = 0;
- string date = currentDate.ToString("dd-MM-yyyy");
- date = date.Replace(":", "").Replace("-", "").TrimStart('0');
- int number = int.Parse(date);
- for (int i = 0, m = (int)Math.Pow(10, date.Length - 1); i < date.Length; i++, m /= 10)
- {
- mult = number / m % 10;
- for (int j = i + 1, n = m / 10; j < date.Length; j++, n /= 10)
- {
- result += mult * (number / n % 10);
- }
- }
- if (result == magicWeight)
- {
- dates.Add(currentDate);
- }
- }
- if (dates.Count > 0)
- {
- foreach (var date in dates)
- {
- Console.WriteLine(date.ToString("dd-MM-yyyy"));
- }
- }
- else
- {
- Console.WriteLine("No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement