听灌多,玄关求条
  • 板块灌水区
  • 楼主kaiweiwang
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/9/7 20:19
  • 上次更新2024/9/7 20:29:47
查看原帖
听灌多,玄关求条
1374349
kaiweiwang楼主2024/9/7 20:19
#include<bits/stdc++.h>
using namespace std;
map<string,int> vis;
int n;
bool check(char s[]){
	int a=-1,b=-1,c=-1,d=-1,e=-1;
	int t=sscanf(s,"%a.%b.%c.%d:%e",&a,&b,&c,&d,&e);
	if(t!=5) return 0;
	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;
	char s2[35];
	sprintf(s2,"%a.%b.%c.%d:%e",a,b,c,d,e);
	int lens=strlen(s);
	bool ok=0;
	for(int i=0;i<lens;i++){
		if(s[i]==s2[i]){
			ok=1;
		}
		else{
			ok=0;
			break;
		}
	}
	return ok;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		char op[1005],ad[1005];
		cin>>op>>ad;
		string t(ad);
		if(op[0]=='S'){
			if(!check(ad)) cout<<"ERR"<<endl;
			else if(vis.count(t)!=0) cout<<"FAIL"<<endl;
			else cout<<"OK"<<endl,vis[t]=i;
		}
		else{
			if(!check(ad)) cout<<"ERR"<<endl;
			else if(vis.count(t)==0) cout<<"FAIL"<<endl;
			else cout<<vis[ad]<<endl;
		}
	}
	return 0;
}

照着题解该都没改对qwq!

2024/9/7 20:19
加载中...