-
Notifications
You must be signed in to change notification settings - Fork 0
/
Euler_019.cs
72 lines (66 loc) · 1.82 KB
/
Euler_019.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Euler_19
{
class Program
{
static int DaysInYear(int x)
{
int DaysInYear = 365;
if (x % 4 == 0)
{
if (x % 100 == 0)
{
if (x % 400 == 0)
DaysInYear++;
}
else
DaysInYear++;
}
return DaysInYear;
}
static int findSundays(int year, int startDay)
{
int totalSundays = 0;
int [] months = new int [13];
months[1]=31;
months[2] =28;
months[3] = 31;
months[4] = 30;
months[5] = 31;
months[6] = 30;
months[7] = 31;
months[8] = 31;
months[9] = 30;
months[10] = 31;
months[11] = 30;
months[12] = 31;
if (DaysInYear(year) == 366)
months[2] = 29;
for (int i=1; i<=12; i++)
{
if (startDay % 7 == 0)
totalSundays++;
startDay = startDay + months[i];
}
return totalSundays;
}
static void Main(string[] args)
{
int yearCurrent = 1901;
int yearEnd = 2000;
int dayCurrent = 2;
int totalSundays = 0;
for (int i=yearCurrent; i<=yearEnd; i++)
{
totalSundays = totalSundays + findSundays(i, dayCurrent);
dayCurrent = (dayCurrent+DaysInYear(i))%7;
}
Console.WriteLine("total sundays is " + totalSundays);
Console.ReadLine();
}
}
}