Добавил:
Оставь надежду всяк сюда поступивший Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
22
Добавлен:
13.01.2019
Размер:
1.35 Кб
Скачать
#include <iostream>
#include <string>
#include <cstdlib>

int main() {
    std::string date;
    std::string array[LIMIT];
    size_t position = 0;
    int index = 0;
    bool isLeap = false;
    bool isValidDate = true;
    int day, month, year;

    std::cin >> date;

    while ( (position = date.find('.')) != std::string::npos ) {
        std::string token = date.substr(0, position);
        array[index] = token;
        date.erase(0, position + 1);
        index += 1;
    }
    array[index] = date;

    day = atoi(array[0].c_str());
    month = atoi(array[1].c_str());
    year = atoi(array[2].c_str());

    if ( year % 4 == 0 ) {
        isLeap = true;
    }
    if ( day < 1 || day > 31 ) {
        isValidDate = false;
    }
    if ( month < 1 || month > 12 ) {
        isValidDate = false;
    }
    if ( month == 2 && day > 29 && isLeap == true ) {
        isValidDate = false;
    }
    if ( month == 2 && day > 28 && isLeap == false ) {
        isValidDate = false;
    }
    if ( month == 4 || month == 6 || month == 9 || month == 11 ) {
        if ( day > 30 ) {
            isValidDate = false;
        }
    }

    if ( isValidDate ) {
        std::cout << "Date valid!" << std::endl;
    } else {
        std::cout << "Invalid date!" << std::endl;
    }

    return 0;
}
Соседние файлы в папке 4
  • #
    13.01.20191.09 Кб234.cbp
  • #
    13.01.2019357 б224.layout
  • #
    13.01.20191.35 Кб22main.cpp