Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Globalization;
- class MagicDates
- {
- private static int GetWeigth(DateTime date) {
- string str = date.ToString("ddMMyyyy");
- int len = str.Length;
- int[] arr = new int[len];
- char[] cArr = str.ToCharArray();
- for (int i = 0; i < len; i++){
- arr[i] = cArr[i] - '0';
- }
- int weigth = 0;
- for (int i = 0; i < len - 1; i++) {
- if (arr[i] != 0) {
- for (int j = i + 1; j < len; j++) {
- weigth += arr[i] * arr[j];
- }
- }
- }
- return weigth;
- }
- static void Main(string[] args)
- {
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
- int startYear = int.Parse(Console.ReadLine());
- int endYear = int.Parse(Console.ReadLine());
- int weigth = int.Parse(Console.ReadLine());
- DateTime startDate = new DateTime(startYear, 1, 1);
- DateTime endDate = new DateTime(endYear, 12, 31);
- bool success = false;
- for (; startDate <= endDate; startDate = startDate.AddDays(1)) {
- if (GetWeigth(startDate) == weigth) {
- Console.WriteLine(startDate.ToString("dd-MM-yyyy"));
- success = true;
- }
- }
- if(!success)
- Console.WriteLine("No");
- }
- }
Add Comment
Please, Sign In to add comment