社区讨论
#13样例过了啊,怎么还错!!!(崩溃)
P7911[CSP-J 2021] 网络连接参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo16jkop
- 此快照首次捕获于
- 2023/10/22 16:01 2 年前
- 此快照最后确认于
- 2023/11/02 15:36 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
map<int,bool>dabiao1;
map<int,bool>dabiao2;
map<string,int>server;
int n;
bool correct;
string s1,s2;
void db1(){
for(int i=0;i<=255;i++){
dabiao1[i]=1;
}
}
void db2(){
for(int i=0;i<=65535;i++){
dabiao2[i]=1;
}
}
void check(int len){
string a,b;
int dian=0,mao=0;
bool flag=0,flag1=1,flag2=1;
for(int i=0;i<len;i++){
if(s2[i]==':'){
if(a.length()!=1&&a[0]=='0'){//考虑前导0
cout<<"ERR"<<endl;
flag2=0;
break;
}
else if(dabiao1[atoi(a.c_str())]!=1||a==" "){//考虑a是否存在
cout<<"ERR"<<endl;
flag2=0;
break;
}
a.clear() ;
flag=1;
mao++;
}
else if(s2[i]=='.'){
dian++;
if(s2[i]==s2[i+1]){//考虑两个"."连一起
cout<<"ERR"<<endl;
flag2=0;
break;
}
else if(a.length()!=1&&a[0]=='0'){//考虑前导0
cout<<"ERR"<<endl;
flag2=0;
break;
}
else if(dabiao1[atoi(a.c_str())]!=1||a==" "){//考虑a是否存在
cout<<"ERR"<<endl;
flag2=0;
break;
}
a.clear() ;
}
else if(flag==0){//在":"前且不为"."时,建立字符串
a+=s2[i];
}
else if(flag){//遇到":"后,则建立b字符串
b+=s2[i];
}
}
if((dabiao2[atoi(b.c_str())]!=1||dian!=3||mao!=1||b[0]=='0')&&flag2!=0){
cout<<"ERR"<<endl;
}
else if(flag2)correct=1;
}
int main(){
// freopen("network4.in","r",stdin);
// freopen("network4.out","w",stdout);
cin>>n;
db1();
db2();
for(int i=1;i<=n;i++){
correct=0;
cin>>s1>>s2;
int len=s2.length();
if(s1=="Server"){
check(len);
if(correct==1){
if(server[s2]==0){
server[s2]=i;
cout<<"OK"<<endl;
}
else if(correct==1&&server[s2]!=0)cout<<"FAIL"<<endl;
}
}
else{
check(len);
if(correct==1){
if(server[s2]!=0)cout<<server[s2]<<endl;
else cout<<"FAIL"<<endl;
}
}
}
//Server 64.84.208.933:56528
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...