#define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mpair make_pair #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; typedef long double ld; const ld epsylon = 1e-9; string from; string to; string cc; string bcc; string attachment; string subject; string body; bool empty(const string& s) { for (int i = 0; i < (int)s.size();++i){ if (s[i] != ' ' && s[i] != '\n' && s[i] != '\r') { return false; } } return true; } //bool empty(const string& s) { // for (int i = 0; i < s.size();++i){ // if (s[i] != ' ' && s[i] != '\n' && s[i] != '\r') { // return false; // } // } // return true; //} bool verify_mail(const string& s){ if (empty(s)) { return true; } if (s[0] == '@' || s[0] == '.') { return false; } int n = (int)s.size() - 1; if (s[n] == '@' || s[n] == '.') { return false; } int numa = 0 ; int posa = -1; for (int i = 0; i < (int)s.size();++i){ if (s[i] == '@'){ numa++; posa = i; } } if (numa != 1) { return false; } if (s[posa - 1] == '.' || s[posa + 1 ] == '.') { return false; } bool has = false; for (int j = posa+ 1; j <(int)s.size();++j) { if (s[j] == '.') { has = true; break; } } if (!has) { return false; } for (int i=1;i> temp) { if (!verify_mail(temp)) { return false; } } return true; } bool valid_body(const string& s) { for (int i=1;i < (int)s.size();++i){ if (s[i] == ' ' && nl(s[i-1])) { return false; } if (nl(s[i]) && s[i-1] == ' ') { return false; } if (s[i] == ' ' && s[i - 1] == ' ') { return false; } } for (int i = 0; i + 2 < (int)s.size();i++){ if (nl(s[i]) && nl(s[i+1]) && nl(s[i+2])) { return false; } } return true; } bool empty_attach(const string& s) { for (int i=0;i+5<(int)s.size();++i){ if (s[i] == 'a' && s[i+1] == 't' && s[i+2] == 't' && s[i+3] == 'a' && s[i+4] == 'c' && s[i+5] == 'h') { if (empty(s.substr(i+6, s.size()))) { return true; } } } return false; } int get_error() { if (empty(from)) { return 1; } if (empty(to) && empty(bcc) && empty(cc)) { return 2; } if (!verify_email_list(from) || !verify_email_list(to) || !verify_email_list(cc) || !verify_email_list(bcc)) { return 3; } if (empty(subject)) { return 100; } if (empty(body)){ return 101; } if (!valid_body(body)) { return 102; } if (empty_attach(body)) { return 103; } return 0; } int main() { freopen("email.in","r",stdin); freopen("email.out","w",stdout); string temp; while (getline(cin, temp)) { istringstream in(temp); string type; in >> temp; if (temp == "from:") { getline (in, from); } else if (temp == "to:") { //parse_to(temp, to); getline (in, to); } else if (temp == "cc:"){ getline(in, cc); //parse_to(temp, cc); } else if (temp == "bcc:"){ //parse_to(temp, bcc); getline(in, bcc); } else if (temp == "attachment:") { getline(in, attachment); if (attachment.size() != 0) { while (getline(cin, temp)) { if (temp.size() == 0) { break; } attachment += "\n" + temp; } } } else if (temp == "subject:") { getline(in, subject); }else if (temp == "body:") { getline(in, temp); if (temp.size() > 0 && temp[0] == ' ') { temp = temp.substr(1, temp.size()); } if (temp != "----"){ body =temp; while (getline(cin, temp)) { if (temp == "----") { break; } body += "\n" + temp; } } } } cout << get_error() << '\n'; return 0; }