请问一下,我这个代码在PTA一直有一个答案错误?
题目是输入一个字符串,判断是否是合法邮箱(格式正确即可,不管是否真的存在)输入的只能是字母、数字、下划线、@以及.五种, @前后只能是字母或者数字,而且.后只能是com, 是则输出YES ,否则输出NO。#include<stdio.h>
#include<string.h>
int main()
{
char em[50];
int i=0,len;
int dui = 0,aite = 0,qita = 0;
scanf("%s",em);
len = strlen(em);
while(1){
if(em[0] == '@'){
printf("NO");
break;
}
while(em[i] != '@'){
if(em[i]=='_' || (em[i]>='a' && em[i]<='z') || (em[i]>='A' && em[i]<='Z') || (em[i]>='0' && em[i]<='9')) dui=1;
else qita = 1;
i++;
if(i==len - 1){
printf("NO");
break;
}
}
if(i==len - 1){
break;
}
if(((em[i-1]>='a' && em[i-1]<='z') || (em[i-1]>='A' && em[i-1]<='Z') || (em[i-1]>='0' && em[i-1]<='9')) && ((em[i+1]>='a' && em[i+1]<='z') || (em[i+1]>='A' && em[i+1]<='Z') || (em[i+1]>='0' && em[i+1]<='9'))){
dui = 1;
}
else{
printf("NO");
break;
}
if(qita == 1){
printf("NO");
break;
}
qita = 0;
i++;
while(em[i] != '.'){
if(em[i]=='_' || (em[i]>='a' && em[i]<='z') || (em[i]>='A' && em[i]<='Z') || (em[i]>='0' && em[i]<='9')) dui=1;
else{
qita = 1;
break;
}
i++;
}
if(qita == 1){
printf("NO");
break;
}
if((em[i+1] != 'c' || em[i+2]!= 'o'|| em[i+3] != 'm') || em[i+4] != '\0'){
printf("NO");
break;
}
else {
printf("YES");
break;
}
}
return 0;
}