为什么本地能过,测试过不了,求助大佬,想申诉
查看原帖
为什么本地能过,测试过不了,求助大佬,想申诉
541553
wangshi楼主2021/11/1 19:29
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
using namespace std;
map<string,int> q;
int main()
{
    freopen("network.in","r",stdin);
    freopen("network.out","w",stdout);
    int n,ser=0,cli=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        char a;
        cin>>a;
        if(a=='S')
        {
            scanf("erver ");
            string s;
            getline(cin,s);
            int shu=0,sum=1;
            bool f=true;
            if(s[0]=='0')
            {
                f=false;
                printf("ERR\n"); 
                continue;               
            }
            for(int j=0;j<s.size();j++)
            {
                if(s[j]>='0'&&s[j]<='9')
                {
                    shu*=10;
                    shu+=s[j]-'0';
                }
                else
                {
                    if(s[j]=='.')
                    {
                        if(sum==4||shu>255)
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;                      
                        }
                    }
                    if(s[j]==':')
                    {
                        if(shu>255||sum!=4)
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;                      
                        }
                        shu=0;
                        if(s[j+1]=='0')
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;              
                        }   
                        for(int k=j+1;k<s.size();k++)
                        {
                            shu*=10;
                            shu+=s[k]-'0';
                        }
                        if(shu>65535)
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;                      
                        }
                        break;
                    }
                    if(s[j+1]=='0')
                    {
                        f=false;
                        printf("ERR\n"); 
                        break;              
                    }
                    sum++;
                    shu=0;
                }
            }
            if(f)
            {
                if(q[s]==0)
                {
                    printf("OK\n");
                    q[s]=i; 
                }
                else
                {
                    printf("FAIL\n");
                }
            }
        } 
        else
        {
            scanf("lient ");
            string s;
            getline(cin,s);
            int shu=0,sum=1;
            bool f=true;
            if(s[0]=='0')
            {
                f=false;
                printf("ERR\n"); 
                continue;               
            }
            for(int j=0;j<s.size();j++)
            {
                if(s[j]>='0'&&s[j]<='9')
                {
                    shu*=10;
                    shu+=s[j]-'0';
                }
                else
                {
                    if(s[j]=='.')
                    {
                        if(sum==4||shu>255)
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;                      
                        }

                    }
                    if(s[j]==':')
                    {
                        if(shu>255)
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;                      
                        }
                        if(sum!=4)
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;                      
                        }
                        shu=0;
                        if(s[j+1]=='0')
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;              
                        }
                        for(int k=j+1;k<s.size();k++)
                        {
                            shu*=10;
                            shu+=s[k]-'0';
                        }
                        if(shu>65535)
                        {
                            f=false;
                            printf("ERR\n"); 
                            break;                      
                        }
                        break;

                    }
                    if(s[j+1]=='0')
                    {
                        f=false;
                        printf("ERR\n"); 
                        break;              
                    }
                    sum++;
                    shu=0;
                }
            }
            if(f)
            {
                if(q[s]!=0)
                {
                    printf("%d\n",q[s]); 
                }
                else
                {
                    printf("FAIL\n");
                }
            }
        }
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
2021/11/1 19:29
加载中...