codeforces 412E E-mail Addresses

Description
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.

Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume that the string contains the letters of some users of the R1 mail. Recovering letters is a tedious mostly manual work. So before you start this process, it was decided to estimate the difficulty of recovering. Namely, we need to calculate the number of different substrings of the saved string that form correct e-mail addresses.

We assume that valid addresses are only the e-mail addresses which meet the following criteria:

the address should begin with a non-empty sequence of letters, numbers, characters ‘_’, starting with a letter;
then must go character ‘@’;
then must go a non-empty sequence of letters or numbers;
then must go character ‘.’;
the address must end with a non-empty sequence of letters.
You got lucky again and the job was entrusted to you! Please note that the substring is several consecutive characters in a string. Two substrings, one consisting of the characters of the string with numbers l1, l1 + 1, l1 + 2, …, r1 and the other one consisting of the characters of the string with numbers l2, l2 + 1, l2 + 2, …, r2, are considered distinct if l1 ≠ l2 or r1 ≠ r2.

Input
The first and the only line contains the sequence of characters s1s2… sn(1 ≤ n ≤ 106) — the saved string. It is guaranteed that the given string contains only small English letters, digits and characters ‘.’, ‘_’, ‘@’.

Output
Print in a single line the number of substrings that are valid e-mail addresses.

Sample Input
Input
gerald.agapov1991@gmail.com
Output
18
Input
x@x.x@x.x_e_@r1.com
Output
8
Input
a___@1.r
Output
1
Input
.asd123__..@
Output
0
Hint
In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.

In the second test case note that the e-mail x@x.x is considered twice in the answer. Note that in this example the e-mail entries overlap inside the string.

粘的题意:问说给出字符串中有几个正确的邮箱,

1.‘@’前非空的字符串,由字符,数字和下划线组成,只能由字符开头
2.’@‘和’.‘中间的字符串非空,只能由字符,数字和下划线组成
3.‘.’后非空字符串,只能有字符组成

解题思路:计算每个@前面字符的个数,以及.后面字符的个数,相乘即为当前这对@和.所满足的个数,不过要注意@和.之间的字符串非空。

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

char a[1000010];

int main ()
{
    int k=0;
    cin>>a;
    int len=strlen(a);
    long long sum=0;
    for (int h = 0; h < len; h++)
    {
        if(a[h]=='@')
        {
            int i=h;
            long long x=0,y=0;
            for(int j=i-1; j>=0; j--)
            {
                if(a[j]=='@'||a[j]=='.')
                    break;
                if((a[j] >='a'&&a[j]<='z')||(a[j] >='A'&&a[j]<='Z'))
                    x++;
            }
            for(int j=i+1; j<len; j++)
            {
                if(a[j]=='@'||a[j]=='_')
                {
                    i=j-1;
                    break;
                }
                if(a[j]=='.')
                {
                    if(j-i==1)
                        break;
                    int l;
                    for(l=j+1; l<len; l++)
                    {
                        if(!((a[l]>='a'&&a[l]<='z')||(a[l]>='A'&&a[l]<='Z')))
                            break;
                        y++;
                    }
                    i=l-1;
                    break;
                }
            }
            sum+=x*y;
        }
    }
    cout<<sum<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值