Добавил:
13246980
Оставь надежду всяк сюда поступивший
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Синников С++ / 2 курс / С++ / 4 / main
.cpp#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;
}