#include #include #include using namespace std; int main () { string line = "x"; regex backupImage ("[!-~]{1,32}"); regex backupFile ("[!-~]{1,32}_[0-9]{1,10}_[A-Za-z]{1,6}"); int lineNum = 0; int imageCount = 0; getline(cin, line); while (cin.good() && (line != "")) { if (line.size() > 32) { cerr << "Line " << lineNum << " too long" << endl; return -1; } if (!regex_match(line, backupImage)) { cerr << "Line " << lineNum << " fails pattern" << endl; return -2; } getline(cin, line); ++lineNum; ++imageCount; if (imageCount > 100000) { cerr << "Line " << lineNum << ": too many images" << endl; return -6; } } if (!cin.good()) { cerr << "Line " << lineNum << " prior I/O error" << endl; return -3; } getline(cin, line); ++lineNum; int fileCount = 0; while (cin.good()) { if (!regex_match(line, backupFile)) { cerr << "Line " << lineNum << " fails 2nd pattern" << endl; return -4; } getline(cin, line); ++lineNum; ++fileCount; if (fileCount > 300000) { cerr << "Line " << lineNum << ": too many files" << endl; return -7; } } if (!cin.eof()) { cerr << "Line " << lineNum << ". Did not reach end of file." << endl; return -5; } cerr << "OK" << endl; return 42; }