求助,WA 12,13,18,19,20五个点
查看原帖
求助,WA 12,13,18,19,20五个点
540148
Universal_xtr楼主2021/10/23 22:39

如题,考场代码长这样(去掉了freopen):

#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
map<string,ll> use;
ll n;
ll conv(string str){
	ll r=0;
	for(ll i=0;i<str.length();i++)r=(r<<1)+(r<<3)+str[i]-48;
	return r;
}
bool valid(string str){
	if(str.find(':')==string::npos or str.find('.')==string::npos)return false;
	string t;
	ll cntdot=0;
	for(ll i=0;i<str.length();i++){
		if(cntdot>3)return false;
		if(str[i]=='.'){
			if(t[0]=='0' and t!="0")return false;
			ll tmp=conv(t);
			if(tmp<0 or tmp>255)return false;
			cntdot+=1;
			t="";
		}
		else if(str[i]==':'){
			if(t[0]=='0' and t!="0")return false;
			ll tmp=conv(t);
			if(tmp<0 or tmp>255)return false;
			cntdot+=1;
			t="";
			if(cntdot<3)return false;
			t=str.substr(i+1,str.length()-i-1);
			if(t.find(':')!=string::npos or t.find('.')!=string::npos)return false;
			if(t[0]=='0' and t!="0")return false;
			tmp=conv(t);
			if(tmp<0 or tmp>65535)return false;
			return true;
		}
		else t+=str[i];
	}
	return true;
}
string op,ad;
int main(){
	//freopen("network.in","r",stdin);
	//freopen("network.out","w",stdout);
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>op>>ad;
		if(op=="Server"){
			if(!valid(ad))cout<<"ERR"<<endl;
			else if(use[ad])cout<<"FAIL"<<endl;
			else{
				cout<<"OK"<<endl;
				use[ad]=i;
			}
		}
		else{
			if(!valid(ad))cout<<"ERR"<<endl;
			else if(!use[ad])cout<<"FAIL"<<endl;
			else cout<<use[ad]<<endl;
		}
	}
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

求助各路神仙,感激不尽!

2021/10/23 22:39
加载中...