描述
电子邮箱具有单独的网络域名,其书写格式也有一定的要求。一般来说,电子邮箱的格式是:用户名@域名。
标准的邮箱格式,例abcxyz@163.com,abcxyz为帐号,163.com为提供邮箱服务的网易域名。
—个完整的Internet邮件地址由以下两个部分组成,格式如下:登录名@主机名.域名
中间用—个表示“在”(at)的符号“@”分开,符号的左边是对方的登录名,右边是完整的主机名,它由主机名与域名组成。其中,域名由几部分组成,每一部分称为一个子域(Subdomain),各子域之间用圆点“.”隔开,每个子域都会告诉用户一些有关这台邮件服务器的信息。
输入描述
输入一行,内容为一个邮箱地址。
输出描述
若输入的邮箱地址合法,则输出”OK”,否则输出“Wrong”。
判断的标准是,@字符和.字符必须要出现,并且不能出现在第一位置和最后一个位置上,并且@要在.的前面,并且这两个字符不能挨着。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| #include<bits/stdc++.h> using namespace std; bool a(char c){ if( (c>=97) && (c<=122) ) { return true; } if( (c>=65) && (c<=90) ) { return true; } if((c>=48) && (c<=57)){ return true; } if( c==95 || c==45 || c==46 || c==64 ) { return true; } return false; } bool b(string in){ if( in.length()<5 ) { return false; } char c = in[0]; if( ((c>=97) && (c<=122)) || ((c>=65) && (c<=90)) ){ int cnt =0; int pos = 0; int count = 0; for(int i=1;i<in.length();i++){ c = in[i]; if(a(c)){ if(c=='@') { cnt ++; pos = i; }else if( (cnt>0) && (c==46) ) { count ++; } }else { return false; } } if( c == 46){ return false; } if( (cnt!=1) || (count<1) || (count>3) ){ return false; } int x,y; x=in.find("@."); y=in.find(".@"); if( x>0 || y>0 ){ return false; } return true; } return false; } int main(){ string s; cin >> s; if(b(s)){ cout << "OK"; }else{ cout << "Wrong"; } }
|