Email code
Problem Description
众所周知,一个正确的邮件地址只包含’.’,’@’和小写字母的拉丁字母,开始和结尾不能是’.’和’@’ ,’.’可以有多个,’@’只能有一个(第一个出现的)。
Input
Output
Sample Input
denglaixianatgmaildotcom dotdotdotatdotdotat aatatt
Sample Output
denglaixian@gmail.com dot..@..at a@att
解析:水题一道,将字符串中的非第一个dot和非最后一个dot转化成‘.’,将将字符串中的非第一个at和非最后一个t转化成@。
#include"stdio.h"
#include"string.h"
int main()
{
char s[1001];
char store[1001],dot1;
int i,at1,j;
while(scanf("%s",s)!=EOF)
{
memset(store,0,sizeof(store));
store[0]=s[0];
int len=strlen(s);
j=1;
at1=1;
for( i=1;i<len-3;)
{
if(s[i]=='a'&&s[i+1]=='t'&&at1)
{
store[j++]='@';
i=i+2;
at1=0;
continue;
}
if(s[i]=='d'&&s[i+1]=='o'&&s[i+2]=='t')
{
store[j++]='.';
i=i+3;
continue;
}
store[j++]=s[i++];
}
if(i<=len-3)
{
if(s[len-3]=='a'&&s[len-2]=='t'&&at1)
{
store[j++]='@';
store[j]=s[len-1];
}
else
{
store[j++]=s[len-3];
store[j++]=s[len-2];
store[j]=s[len-1];
}
}
else
{
if(i==len-2)
{
store[j++]=s[len-2];
store[j]=s[len-1];
}
if(i==len-1)
store[j]=s[len-1];
}
printf("%s\n",store);
}
return 0;
}