#include #include "validation.h" // Check that: // - first line is an int between 1 and 100 // - next lines are under format "Name mm-dd" with // * Name a string using the characters [a-zA-Z] // * mm describing a month (01, 02,..., 11, 12) // * dd describing a day (01, 02,..., 30, 31) // - dd matches the month (month 02, max value of dd = 28, month 04, 06, // 09 and 11, max value of dd = 30) static const std::regex name_regex("[a-zA-Z]+"); static const std::regex date_regex("[0-1][0-9]-[0-3][0-9]"); int main(int argc, char **argv) { InputValidator v; int n = v.read_int(1, 100); v.newline(); for (int i = 0; i < n; i++) { string name = v.read_string(1, 20); size_t size = name.length(); if (!regex_search(name, name_regex)) v.WA("Not a valid name (should be written using [a-zA-Z] characters only)."); v.space(); string date = v.read_string(5, 5); if (!std::regex_match(date, date_regex)) v.WA("Not a valid date (should be written under mm-dd format)."); if(date[2] != '-') v.WA("Date ", date, " should be separated by a -"); string month_str = date.substr(0, 2); int month = stoi(month_str); string day_str = date.substr(3, 2); int day = stoi(day_str); if (month < 0 || month > 12) v.WA("Not a valid month number (should be between 1 and 12)."); if (month == 2 && day > 28) v.WA("Not a valid day number (should be between 1 and 28 for February)."); if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30) v.WA("Not a valid day number (should be between 1 and 30 for April, June, September or November)."); if (day < 0 || day > 31) v.WA("Not a valid day number (should be between 1 and 31 for January, March, May, July, August, October or December)."); v.newline(); } }