65pts求调
查看原帖
65pts求调
252430
属性空楼主2023/2/21 17:28
#include<bits/stdc++.h>
using namespace std;
struct node{
	int a,b,c,d,e,bh;
}r[3000];
int u=0,er=0;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		string op,ab;
		cin>>op>>ab;
		if(op=="Server"){
			int a=0,b=0,c=0,d=0,e=0,te=1,pe=0,jp=0;
			for(int j=0;j<ab.length();j++){
				if(ab[j]=='.'||ab[j]==':'){
					te++;
					if(ab[j]==':'){
						pe++;
					}
				}else{
					if(te==1){
						if(a==0&&ab[j]=='0'&&ab[j+1]!='.'){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						a=a*10+ab[j]-'0';
					}else if(te==2){
						if(b==0&&ab[j]=='0'&&ab[j+1]!='.'){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						b=b*10+ab[j]-'0';
					}else if(te==3){
						if(c==0&&ab[j]=='0'&&ab[j+1]!='.'){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						c=c*10+ab[j]-'0';
					}else if(te==4){
						if(d==0&&ab[j]=='0'&&ab[j+1]!=':'){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						d=d*10+ab[j]-'0';
					}else if(te==5){
						if(e==0&&ab[j]=='0'&&j+1<ab.length()){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						e=e*10+ab[j]-'0';
					}
				}
			}
			if(jp)continue;
				if(pe>=2||pe<=0||te>=6||a>255||b>255||c>255||d>255||e>65535){
					cout<<"ERR"<<endl;
					continue;
				}
				int temp=0;
				for(int j=1;j<=u;j++){
					if(a==r[j].a&&b==r[j].b&&c==r[j].c&&d==r[j].d&&e==r[j].e){
						temp=1;
					}
				}
				if(temp){
					cout<<"FAIL"<<endl;
					continue;
				}
				r[++u].a=a;
				r[u].b=b;
				r[u].c=c;
				r[u].d=d;
				r[u].e=e;
				r[u].bh=i;
				cout<<"OK"<<endl;
			}else{
			int a=0,b=0,c=0,d=0,e=0,te=1,pe=0,jp=0;
			for(int j=0;j<ab.length();j++){
				if(ab[j]=='.'||ab[j]==':'){
					te++;
					if(ab[j]==':'){
						pe++;
					}
				}else{
					if(te==1){
						if(a==0&&ab[j]=='0'&&ab[j+1]!='.'){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						a=a*10+ab[j]-'0';
					}else if(te==2){
						if(b==0&&ab[j]=='0'&&ab[j+1]!='.'){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						b=b*10+ab[j]-'0';
					}else if(te==3){
						if(c==0&&ab[j]=='0'&&ab[j+1]!='.'){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						c=c*10+ab[j]-'0';
					}else if(te==4){
						if(d==0&&ab[j]=='0'&&ab[j+1]!=':'){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						d=d*10+ab[j]-'0';
					}else if(te==5){
						if(e==0&&ab[j]=='0'&&j+1<ab.length()){
							cout<<"ERR"<<endl;
							jp=1;
							break;
						}
						e=e*10+ab[j]-'0';
					}
			}
		}
			if(jp)continue;
				if(pe>=2||pe<=0||te>=6||a>255||b>255||c>255||d>255||e>65535){
					cout<<"ERR"<<endl;
					continue;
				}
				int temp=0,hao=0;
				for(int j=1;j<=u;j++){
					if(a==r[j].a&&b==r[j].b&&c==r[j].c&&d==r[j].d&&e==r[j].e){
						temp=1;
						hao=r[j].bh;
						break;
					}
				}
				if(!temp){
					cout<<"FAIL"<<endl;
					continue;
				}
				cout<<hao<<endl;
	}
	}
	return 0;
}

P7911 [CSP-J 2021] 网络连接 rt

2023/2/21 17:28
加载中...