* Computer Science/Project Euler

project euler 19. problem

soicem 2016. 7. 29. 11:55

문제 : 다음은 달력에 관한 몇 가지 일반적인 정보입니다 (필요한 경우 좀 더 연구를 해 보셔도 좋습니다).

  • 1900년 1월 1일은 월요일이다.
  • 4월, 6월, 9월, 11월은 30일까지 있고, 1월, 3월, 5월, 7월, 8월, 10월, 12월은 31일까지 있다.
  • 2월은 28일이지만, 윤년에는 29일까지 있다.
  • 윤년은 연도를 4로 나누어 떨어지는 해를 말한다. 하지만 400으로 나누어 떨어지지 않는 매 100년째는 윤년이 아니며, 400으로 나누어 떨어지면 윤년이다

20세기 (1901년 1월 1일 ~ 2000년 12월 31일) 에서, 매월 1일이 일요일인 경우는 총 몇 번입니까?



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
days = ["monday""Tuesday""wednesday""Thursday""Friday""Saturday""Sunday"]
months = [312831303130313130313031]
 
dayN = 0
result = {}
 
for year in range(19002001):
 
    monthN = 0
 
    if year %4==0:
        if year % 100 == 0:
            if year % 400 ==0:
                months[1= 29
            else:
                months[1= 28
        else:
            months[1= 29
        
        
    elif months[1== 29:
        months[1= 28
    tmp = 0
    for month in months:
        monthN +=1
 
        for i in range(0, month):
            print "date : year", year, "/ month :", monthN, "/ day :", (i+1), days[dayN%7]
            if i+1 == 1 and days[dayN%7== "Sunday":
                
                tmp +=1
            dayN +=1
    result[year] = tmp
print result 
 
sum = 0
 
for year in range(19002001):
    sum += result.get(year)
print sum - result.get(1900)        
cs



date : year 2000 / month : 12 / day : 29 Friday

date : year 2000 / month : 12 / day : 30 Saturday

date : year 2000 / month : 12 / day : 31 Sunday

{1900: 2, 1901: 2, 1902: 1, 1903: 3, 1904: 1, 1905: 2, 1906: 2, 1907: 2, 1908: 2, 1909: 1, 1910: 1, 1911: 2, 1912: 2, 1913: 1, 1914: 3, 1915: 1, 1916: 1, 1917: 2, 1918: 2, 1919: 1, 1920: 2, 1921: 1, 1922: 2, 1923: 2, 1924: 1, 1925: 3, 1926: 1, 1927: 1, 1928: 3, 1929: 2, 1930: 1, 1931: 3, 1932: 1, 1933: 2, 1934: 2, 1935: 2, 1936: 2, 1937: 1, 1938: 1, 1939: 2, 1940: 2, 1941: 1, 1942: 3, 1943: 1, 1944: 1, 1945: 2, 1946: 2, 1947: 1, 1948: 2, 1949: 1, 1950: 2, 1951: 2, 1952: 1, 1953: 3, 1954: 1, 1955: 1, 1956: 3, 1957: 2, 1958: 1, 1959: 3, 1960: 1, 1961: 2, 1962: 2, 1963: 2, 1964: 2, 1965: 1, 1966: 1, 1967: 2, 1968: 2, 1969: 1, 1970: 3, 1971: 1, 1972: 1, 1973: 2, 1974: 2, 1975: 1, 1976: 2, 1977: 1, 1978: 2, 1979: 2, 1980: 1, 1981: 3, 1982: 1, 1983: 1, 1984: 3, 1985: 2, 1986: 1, 1987: 3, 1988: 1, 1989: 2, 1990: 2, 1991: 2, 1992: 2, 1993: 1, 1994: 1, 1995: 2, 1996: 2, 1997: 1, 1998: 3, 1999: 1, 2000: 1}

171

'* Computer Science > Project Euler' 카테고리의 다른 글

project euler 21. problem  (0) 2016.08.01
project euler 20. problem  (0) 2016.07.29
project euler 18. problem  (0) 2016.07.28
project euler 17. problem  (0) 2016.07.27
project euler 16. problem  (0) 2016.07.26