P7911 [CSP-J 2021] 网络连接 65tps
  • 板块灌水区
  • 楼主GreenMelon
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/10/3 20:30
  • 上次更新2024/10/3 22:29:12
查看原帖
P7911 [CSP-J 2021] 网络连接 65tps
970141
GreenMelon楼主2024/10/3 20:30

前导零已解决。

#include<bits/stdc++.h>
#define ll long long
#define ts to_string
using namespace std;
map<string, int> m;
int cnt;
int main(){
	int t;
	cin>>t;
	for(cnt=1;cnt<=t;cnt++){
		string op;
		cin>>op;
		if(op=="Server"){
			string s;
			cin>>s;
			ll a, b, c, d, e;
			ll f=sscanf(s.c_str(), "%lld.%lld.%lld.%lld:%lld", &a, &b, &c, &d, &e);
			string ss;
			ss=ts(a)+'.'+ts(b)+'.'+ts(c)+'.'+ts(d)+':'+ts(e);
			if(ss!=s) goto err;
			if(f!=5) goto err;
			if(a>255 || a<0) goto err;
			if(b>255 || b<0) goto err;
			if(c>255 || c<0) goto err;
			if(d>255 || d<0) goto err;
			if(e>65535 || e<0) goto err;
			if(m[s]) goto fail;
			m[s]=cnt;
			cout<<"OK"<<endl;
			continue;
			
		}
		else if(op=="Client"){
			string s;
			cin>>s;
			ll a, b, c, d, e;
			ll f=sscanf(s.c_str(), "%lld.%lld.%lld.%lld:%lld", &a, &b, &c, &d, &e);
			if(f!=5) goto err;
			if(a>255 || a<0) goto err;
			if(b>255 || b<0) goto err;
			if(c>255 || c<0) goto err;
			if(d>255 || d<0) goto err;
			if(e>65535 || e<0) goto err;
			if(!m[s]) goto fail;
			cout<<m[s]<<endl;
			continue;
		}
		err:
			cout<<"ERR"<<endl;
			continue;
		fail:
			cout<<"FAIL"<<endl;
			continue;
		
	}
	return 0;
}
2024/10/3 20:30
加载中...