Jabber ID(codeforce)

题目连接:http://codeforces.com/contest/21/problem/A

题目大意:判断字符串是否符合要求

题目思路:直接处理字符串

A. Jabber ID
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where

  • <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive.
  • <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive.
  • <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <resource> is between 1 and 16, inclusive.

There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.

Your task is to write program which checks if given string is a correct Jabber ID.

Input

The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.

Output

Print YES or NO.

Sample test(s)
Input
mike@codeforces.com
Output
YES
Input
john.smith@codeforces.ru/contest.icpc/12
Output
NO

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
bool flag=true;
void parse_user(string s)
{
    if(s.size()<1||s.size()>16)
    {
        flag=false;
        return ;
    }

    for(int i=0; i<s.size(); i++)
    {
        if(!isalpha(s[i])&&!isdigit(s[i])&&s[i]!='_')
        {
            flag=false;
            return ;
        }
    }
}
void parse_host(string s)
{
    if(s.size()<1||s.size()>32)
    {
        flag=false;
        return ;
    }
    string cc;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='.')
        {
            if(cc.size()<1||cc.size()>16)
            {
                flag=false;
                return ;
            }
            for(int j=0; j<cc.size(); j++)
            {
                if(!isalpha(cc[j])&&!isdigit(cc[j])&&cc[j]!='_')
                {
                    flag=false;
                    return ;
                }
            }
            cc="";
        }
        else
            cc+=s[i];
    }
    if(cc.size()<1||cc.size()>16)
    {
        flag=false;
        return ;
    }
    for(int j=0; j<cc.size(); j++)
    {
        if(!isalpha(cc[j])&&!isdigit(cc[j])&&cc[j]!='_')
        {
            flag=false;
            return ;
        }
    }
}
void parse_res(string s)
{
    if(s.size()<1||s.size()>16)
        flag=false;
    for(int i=0; i<s.size(); i++)
    {
        if(!isalpha(s[i])&&!isdigit(s[i])&&s[i]!='_')
        {
            flag=false;
            return ;
        }
    }
}
int main()
{
    string str;
    string username,hostname,resource;
    while(cin>>str)
    {
        flag=true;
        int cur=0;
        while(cur<str.size()&&str[cur]!='@')
        {
            username+=str[cur];
            cur++;
        }
        if(cur>=str.size())
        {
            flag=false;
        }
        parse_user(username);
        cur++;
        while(cur<str.size()&&str[cur]!='/')
        {
            hostname+=str[cur];
            cur++;
        }
        parse_host(hostname);
        if(cur<str.size())
        {
            cur++;
            while(cur<str.size())
            {
                resource+=str[cur];
                cur++;
            }
            parse_res(resource);
        }
        if(flag)
            printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值