提交时间:2021-12-06 18:37:37

运行 ID: 33508

#include <bits/stdc++.h> using namespace std; int n; map<string,int> WJJ; inline bool check(string s) { int len = s.length(); long long tmp = 0; int cnt1=0, cnt2=0, cnt3=0; for(int i=0; i<len; i++) { if((i==0 || s[i-1]=='.' || s[i-1]==':') && s[i]>='0' && s[i]<='9') cnt3++; if(s[i]=='.' || s[i]==':') { if(s[i] == '.') cnt1++; else if(s[i] == ':') cnt2++; if(cnt1<3 && cnt2) return false; if(!cnt3) return false; if(0<=tmp && tmp<=255) { tmp = 0; continue; } else return false; } else if(s[i]<'0' || s[i]>'9') return false; if(i && !tmp && s[i-1]=='0') return false; tmp = tmp*10+s[i]-'0'; } if(cnt1!=3 || cnt2!=1 || cnt3!=5) return false; if(0<=tmp && tmp<=65535) return true; else return false; } int main() { scanf("%d", &n); for(int i=1; i<=n; i++) { string cpt, adr; cin >> cpt >> adr; if(!check(adr)) printf("ERR\n"); else if(cpt == "Server") { if(WJJ.count(adr)) printf("FAIL\n"); else { WJJ[adr] = i; printf("OK\n"); } } else if(cpt == "Client") { if(WJJ.count(adr)) printf("%d\n", WJJ[adr]); else printf("FAIL\n"); } } return 0; }