666纯语法题
2025-09-01 14:52:42
发布于:北京
2阅读
0回复
0点赞
纯粹的语法题,模拟的方面不难(
上代码!!!
关注我
#include <bits/stdc++.h>
using namespace std;
string x[1010];
int id[1010];
bool check(string s){
int a,b,c,d,e;
if(sscanf(s.c_str(),"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e)!=5) return false;
if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535) return false;
stringstream ss;
ss<<a<<'.'<<b<<'.'<<c<<'.'<<d<<':'<<e;
return ss.str()==s;
}
int main(){
int n;
cin>>n;
int t=1;
for(int i=1;i<=n;i++){
string op,ad;
cin>>op>>ad;
if(op=="Server"){
int ok=1;
for(int i=t;i>=1;i--){
if(ad==x[i]){
ok=0;
break;
}
}
if(!check(ad)) cout<<"ERR"<<endl;
else if(ok==1){
id[t]=i;
x[t]=ad;
t++;
cout<<"OK"<<endl;
}
else cout<<"FAIL"<<endl;
}
else{
int ok=0;
for(int i=t;i>=1;i--){
if(ad==x[i]){
ok=id[i];
break;
}
}
if(!check(ad)) cout<<"ERR"<<endl;
else if(ok!=0){
cout<<ok<<endl;
}
else cout<<"FAIL"<<endl;
}
}
return 0;
}
这里空空如也
有帮助,赞一个