您的位置:首页 > 其它

codeforces 21A Jabber ID

2015-09-07 22:40 267 查看
A. Jabber ID

time limit per test
0.5 second

memory limit per test
256 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.

The content of square brackets is optional — it can be present or can be absent.

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>
 using namespace std;
 #include<string.h>
 int main()
 {
      char s[150];
      int i,k,k1,a[200],s8,j,s1,s2,s3,s4,s5,s6,s7;
      while(cin>>s)
      {k=-1,k1=-1;
      for(i=0;i<strlen(s);i++)
          if(s[i]=='@')k=i;
      if(k==-1||k==strlen(s)-1)cout<<"NO\n";//判断是否有@或@为最后一位
      else
      { if(k<1||k>16)s8=0;
        else s8=1;//判断<username>的大小是否为1~16;
          for(i=k;i<strlen(s);i++)
          if(s[i]=='/'){k1=i;break;}
          for(i=0;i<k;i++)
            if(s[i]>='0'&&s[i]<='9'||s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z'||s[i]=='_')
                s1=1;
                else  {s1=0;break;}//判断<username>的字符是否正确;
            if(k1==-1)//判断@后面是否存在‘/’;
            {
                if(strlen(s)-k-1>32)
                   s4=0;
                   else s4=1;//判断<hostname>的大小是否为1~32;
                     j=0;s2=1;
                    for(i=k;i<strlen(s);i++)
                        if(s[i]=='.'||s[i]==0||s[i]=='@')
                           a[j++]=i;
                     for(i=0;i<j-1;i++)
                     if(a[i+1]-a[i]-1<1||a[i+1]-a[i]-1>16)
                           s2=0;//判断每两个‘.’之间的字符串大小是否为1~16;
                    for(i=k+1;i<strlen(s);i++)
                         if(s[i]!='.')
                         if(s[i]>='0'&&s[i]<='9'||s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z'||s[i]=='_')
                              s3=1;
                            else  {s3=0;break;}//判断<hostname>的字符是否正确;
                           s7=1;
                      for(i=k;i<strlen(s);i++)
                    if(s[i]=='.')
                        { if(s[i+1]>='0'&&s[i+1]<='9'||s[i+1]>='A'&&s[i+1]<='Z'||s[i+1]>='a'&&s[i+1]<='z'||s[i+1]=='_')
                               s7=1;
                            else {s7=0; break;}
                        }//判断‘.’后面是否有字符,若无‘.’,则也s7=1;
                       // cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<" "<<s7<<" "<<s8<<endl;
                    if(s1&&s2&&s3&&s4&&s7&&s8)cout<<"YES\n";
                    else cout<<"NO\n";

            }
            else
            { int f;
               if(k1-k-1>32)
                   s4=0;
                   else s4=1;//判断<hostname>的大小是否为1~32;
                j=0;s2=1;
               s7=1;
                for(i=k;i<k1;i++)
                    if(s[i]=='.')
                        { if(s[i+1]>='0'&&s[i+1]<='9'||s[i+1]>='A'&&s[i+1]<='Z'||s[i+1]>='a'&&s[i+1]<='z'||s[i+1]=='_')
                               s7=1;
                               else {s7=0; break;}
                        }//判断‘.’后面是否有字符,若无‘.’,则也s7=1;
                    for(i=k;i<k1;i++)
                   if(s[i]=='.'||s[i]==0||s[i]=='@')
                            a[j++]=i;
                     for(i=0;i<j-1;i++)
                     if(a[i+1]-a[i]-1<1||a[i+1]-a[i]-1>16)
                         s2=0;//判断每两个‘.’之间的字符串大小是否为1~16;
                    for(i=k+1;i<k1;i++)
                         if(s[i]!='.')
                         if(s[i]>='0'&&s[i]<='9'||s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z'||s[i]=='_')
                              s3=1;
                            else  {s3=0;break;}//判断<hostname>的字符是否正确;
                            if(strlen(s)-k1-1<1||strlen(s)-k1-1>16)s5=0;
                            else s5=1;//判断<resource>的大小是否为1~16;
                            for(i=k1+1;i<strlen(s);i++)
                                 if(s[i]>='0'&&s[i]<='9'||s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z'||s[i]=='_')
                              s6=1;
                            else  {s6=0;break;}//判断<resource>的字符是否正确;
                           // cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<" "<<s5<<" "<<s6<<" "<<s7<<" "<<s8<<endl;
                            if(s8&&s1&&s2&&s3&&s4&&s5&&s6&&s7)
                                cout<<"YES\n";
                           else cout<<"NO\n";
            }
      }
      }
     return 0;
 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: