没切
这题恶心的点死多……
首先,你这数据不能一次性让我把bug改完吗?浪费lg评测资源,该罚
然后
进入正题
我踩的坑
- 两种机用同一个编号
- 中间会爆int,要在过程中就判掉
- 开头可能出现.这种
毒瘤玩楞
然后比2023 csp-j T3 好写多了
#include<bits/stdc++.h>
using namespace std;
string s1="Server";
map<string,int> ma;
bool g(string s){
int i=0,p=0;
bool flag=0;
if(s[i]<'0'||s[i]>'9')return 0;
for(;i<s.size();i++){
if(s[i]=='.')break;
else if(s[i]=='0'&&p==0){
if(flag)return 0;
flag=1;
}else if(s[i]>='0'&&s[i]<='9'){
if(flag)return 0;
p=p*10+s[i]-'0';
}else return 0;
if(p>255)return 0;
}
p=0;flag=0;
if(s[++i]<'0'||s[i]>'9')return 0;
if(i>=s.size())return 0;
for(;i<s.size();i++){
if(s[i]=='.')break;
else if(s[i]=='0'&&p==0){
if(flag)return 0;
flag=1;
}else if(s[i]>='0'&&s[i]<='9'){
if(flag)return 0;
p=p*10+s[i]-'0';
}else return 0;
if(p>255)return 0;
}
p=0;flag=0;
if(s[++i]<'0'||s[i]>'9')return 0;
if(i>=s.size())return 0;
for(;i<s.size();i++){
if(s[i]=='.')break;
else if(s[i]=='0'&&p==0){
if(flag)return 0;
flag=1;
}else if(s[i]>='0'&&s[i]<='9'){
if(flag)return 0;
p=p*10+s[i]-'0';
}else return 0;
if(p>255)return 0;
}
p=0;flag=0;
if(s[++i]<'0'||s[i]>'9')return 0;
if(i>=s.size())return 0;
for(;i<s.size();i++){
if(s[i]==':')break;
else if(s[i]=='0'&&p==0){
if(flag)return 0;
flag=1;
}else if(s[i]>='0'&&s[i]<='9'){
if(flag)return 0;
p=p*10+s[i]-'0';
}else return 0;
if(p>255)return 0;
}
p=0;flag=0;
if(s[++i]<'0'||s[i]>'9')return 0;
if(i>=s.size())return 0;
for(;i<s.size();i++){
if(s[i]=='0'&&p==0){
if(flag)return 0;
flag=1;
}else if(s[i]>='0'&&s[i]<='9'){
if(flag)return 0;
p=p*10+s[i]-'0';
}else return 0;
if(p>65535)return 0;
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
freopen("1.out","w",stdout);
for(int i=1;i<=n;i++){
string op,ad;
cin>>op>>ad;
if(op==s1){
if(g(ad)){
if(ma[ad]) cout<<"FAIL\n";
else ma[ad]=i,cout<<"OK\n";
}else cout<<"ERR\n";
}else{
if(g(ad)){
if(ma[ad]) cout<<ma[ad]<<'\n';
else cout<<"FAIL\n";
}else cout<<"ERR\n";
}
}
}
标签:return,int,P7911,flag,&&,255,size
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18455000