运行时报错,求助
查看原帖
运行时报错,求助
977956
JeiMin楼主2024/8/13 20:52
#include <bits/stdc++.h>
using namespace std;

int n=0,l=0;

struct Node{
    string op,ad;
};

Node lst[1005];

string ser[1005];

int strToInt(string a){//½«stirngÊä³ö³ÉÊý×Ö

    int cnt=0;
    for (int i=0;i<a.size();i++){
        cnt = cnt*10 + int(a[i]-'0');
    }
    return cnt;
}

bool neg(string str){
    if(str[0]=='-') return 1;
    else return 0;
}

bool haveZero(string str) {
    if (str.size() == 1 && str[0] == '0') return 0;
    else if (str[0] == '0') return 1;
    return 0;
}

bool isElse(string str){
    bool cnt=0;
    for(int i=0;i<str.size();i++){
        int t=0;t=int(str[i]-'0');
        if (t<0 or t>9){
            return 1;
        }
    }
    return 0;
}

bool ifabcd(string str){

    if (haveZero(str) or neg(str) or isElse(str)){
        return 0;
    }

    int num=strToInt(str);
    if (num<0 or num>255) return 0;

    return 1;
}

bool ife(string str){
    if (haveZero(str) or neg(str) or isElse(str)) return 0;

    int num=strToInt(str);
    if (num<0 or num>65535) return 0;

    return 1;
}

bool could(string ad){
    int point=0,t=0,num=0;
    string str=0;

    for (int i=0;i<ad.size();i++){
        if (ad[i]=='.' and t<4){

            t++;
            str="";
            for (int j=0;j<point;j++){
                str=str+ad[j];
            }
            num = strToInt(str);
            point = i;
            if (!ifabcd(str)){
                return 0;
            }
        }
        else if (ad[i]==';' and t==4){
            t++;
            str="";
            for (int j=0;j<point;j++){
                str=str+ad[j];
            }
            num = strToInt(str);
            point = i;
            if (!ife(str)){
                return 0;
            }
        }
    }

    return 1;
}




void server(string ad){
    if (!could(ad)){
        cout <<"ERR"<<'\n';
        return;
    }
    else{
        for (int i=0;i<l;i++){
            if (ser[i]==ad){
                cout <<"FAIL"<<'\n';
                return;
            }
        }
    }

    ser[l]=ad;
    l++;

    cout <<"OK" <<'\n';
    return;

}

void client(string ad){
    if (!could(ad)){
        cout <<"ERR"<<'\n';
        return;
    }
    else{
        for (int i=0;i<l;i++){
            if (ser[i]==ad){
                cout <<i+1<<'\n';
                return;
            }
        }
    }

    cout <<"FALL" <<'\n';
    return;
}

void serverOrClient(string op,string ad){
    if (op=="Server"){
        server(ad);
    }
    else client(ad);
}

int main(){
    cin >>n;
    for (int i=0;i<n;i++){
        cin >>lst[i].op >>lst[i].ad;
        serverOrClient(lst[i].op,lst[i].ad);
    }

    return 0;
}

2024/8/13 20:52
加载中...