记录编号 574089 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [CSP 2021J]网络连接 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2022-07-29 21:21:23 内存使用 0.00 MiB
显示代码纯文本
#include <iostream> 
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
map<string,int>m;
int n;
bool e(char ch[]){
	int a,b,c,d,e;
	a = b = c = d = e = -1;
	sscanf(ch,"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
	if(a == -1 || b == -1 || c == -1 || d == -1 || e == -1)return 0;
	char f[30];
	if(a < 0 || a > 255) return 0;
	if(b < 0 || b > 255) return 0;
	if(c < 0 || c > 255) return 0;
	if(d < 0 || d > 255) return 0;
	if(e < 0 || e > 65535) return 0;
	sprintf(f,"%d.%d.%d.%d:%d",a,b,c,d,e);
	int l = strlen(ch);
	if(l != strlen(f))return 0;
	for(int i = 0;i < l;i++){
		if(ch[i] != f[i]){
			return 0;
		}
	}
	return 1;
}
int main(){
	freopen("csp2021pj_network.in","r",stdin);
	freopen("csp2021pj_network.out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		char a[10],ch[30];
		cin>>a>>ch;
		string c(ch);
		if(!e(ch)){
			cout<<"ERR"<<endl;
			continue;
		}
		if(a[0] == 'S'){
			if(!m.count(c)){
				cout<<"OK"<<endl;
				m[c] = i;
			}
			else cout<<"FAIL"<<endl;
		}
		else{
			if(m.count(c))
				cout<<m[c]<<endl;
			else cout<<"FAIL"<<endl;
		}
	}
	
	return 0;
}