輸入一個字符串,判斷是否是合法郵箱(格式正確即可,不管是否真的存在)輸入的只能是字母、數字、下划線、@以及.五種, @前后只能是字母或者數字,而且.后只能是com, 是則輸出YES ,否則輸出NO。
輸入格式:
一串字符。
輸出格式:
對每個輸入,輸出YES或NO。
輸入樣例:
adf12@qw213.com
輸出樣例:
YES
1 #include<iostream> 2 #include<string> 3 #include<regex> 4 using namespace std; 5 int main() 6 { 7 string s; 8 cin >> s; 9 regex r("[a-zA-Z0-9\_]+@[a-zA-Z0-9]+(\.(com))"); 10 if (regex_match(s, r)) 11 cout << "YES"; 12 else 13 cout << "NO"; 14 return 0; 15 }