По разделам

 

Решение задачи Proc 53


Используя функцию IsLeapYear из задания Proc52, описать функцию
MonthDays(M, Y) целого типа, которая возвращает количество дней для
M-го месяца года Y (1 ≤ M ≤ 12, Y > 0 — целые числа). Вывести значение
функции MonthDays для данного года Y и месяцев M1, M2, M3.

Код (C/C++)

#include <bits/stdc++.h>

using namespace std;

bool func(int y)
{
    if ((y%4 == 0) && !(y%100 == 0 && y%400 != 0)){
        return 1;
    }
    else
        return 0;
}

int main()
{
    int y, m;
    cin >> y;
    for(int i = 0 ; i < 3; ++i){
        cin >> m;
        if(func(y)){
            switch(m){
                case 1: cout << 31; break;
                case 2: cout << 29; break;
                case 3: cout << 31;break;
                case 4: cout << 30;break;
                case 5: cout << 31;break;
                case 6: cout << 30;break;
                case 7: cout << 31;break;
                case 8: cout << 31;break;
                case 9: cout << 30;break;
                case 10:cout << 31;break;
                case 11: cout << 30;break;
                case 12: cout << 31; break;
            }
        }else{
            switch(m){
                case 1: cout << 31; break;
                case 2: cout << 28; break;
                case 3: cout << 31;break;
                case 4: cout << 30;break;
                case 5: cout << 31;break;
                case 6: cout << 30;break;
                case 7: cout << 31;break;
                case 8: cout << 31;break;
                case 9: cout << 30;break;
                case 10:cout << 31;break;
                case 11: cout << 30;break;
                case 12: cout << 31; break;
            }
        }
    }
    return 0;
}

Код (Python)

import random

L = [2016,300,1300,1900,1200,2000,2018]

def IsLeapYear(Y):
    result = False
    if (Y%4 == 0) and not(Y%100 == 0 and Y%400 != 0):
        result = True
    return result

def MonthDays(M,Y):
    if IsLeapYear(Y) and M == 2:
        Days = 29
    else:
        m = {
            1: 31,
            2: 28,
            3: 31,
            4: 30,
            5: 31,
            6: 30,
            7: 31,
            8: 31,
            9: 30,
            10: 31,
            11: 30,
            12: 31
        }
        try:
            Days = m[M]
        except KeyError as e:
            print('Ошибка')
    return Days

for year in L:
    s = "не високосный"
    if IsLeapYear(year):
        s = "високосный"
    print(year," : ",s)

    list_rnd = list(range(1, 13))
    random.shuffle(list_rnd)
    list_rnd = list_rnd[:3]
    for month in list_rnd:
        D = MonthDays(month,year)
        print("Month -> ",month," : Days -> ",D)
									




Proc. Абрамян
Proc 1 Просмотров: 6816
Proc 2 Просмотров: 5265
Proc 3 Просмотров: 5359
Proc 4 Просмотров: 4521
Proc 5 Просмотров: 3544
Proc 6 Просмотров: 4823
Proc 7 Просмотров: 4064
Proc 8 Просмотров: 3177
Proc 9 Просмотров: 3295
Proc 10 Просмотров: 3036
Proc 11 Просмотров: 3137
Proc 12 Просмотров: 2323
Proc 13 Просмотров: 2571
Proc 14 Просмотров: 2822
Proc 15 Просмотров: 2028
Proc 16 Просмотров: 3080
Proc 17 Просмотров: 2679
Proc 18 Просмотров: 2555
Proc 19 Просмотров: 2574
Proc 20 Просмотров: 3370
Proc 21 Просмотров: 3486
Proc 22 Просмотров: 2611
Proc 23 Просмотров: 2590
Proc 24 Просмотров: 1835
Proc 25 Просмотров: 2208
Proc 26 Просмотров: 1979
Proc 27 Просмотров: 2171
Proc 28 Просмотров: 1890
Proc 29 Просмотров: 2080
Proc 30 Просмотров: 2604
Proc 31 Просмотров: 1818
Proc 32 Просмотров: 1375
Proc 33 Просмотров: 1399
Proc 34 Просмотров: 1831
Proc 35 Просмотров: 1306
Proc 36 Просмотров: 1789
Proc 37 Просмотров: 1640
Proc 38 Просмотров: 1333
Proc 39 Просмотров: 1228
Proc 40 Просмотров: 2003
Proc 41 Просмотров: 2023
Proc 42 Просмотров: 1266
Proc 43 Просмотров: 1235
Proc 44 Просмотров: 1147
Proc 45 Просмотров: 1278
Proc 46 Просмотров: 1159
Proc 47 Просмотров: 1213
Proc 48 Просмотров: 945
Proc 49 Просмотров: 1200
Proc 50 Просмотров: 2214
Proc 51 Просмотров: 1815
Proc 52 Просмотров: 1829
Proc 53 Просмотров: 1356
Proc 54 Просмотров: 1392
Proc 55 Просмотров: 1299
Proc 56 Просмотров: 1896
Proc 57 Просмотров: 1648
Proc 58 Просмотров: 1312
Proc 59 Просмотров: 1262
Proc 60 Просмотров: 1534

Комментарии

Чтобы написать комментарии вам нужно войти в систему или зарегистрироваться



Заявка на расчет