提交时间:2021-12-13 13:56:39

运行 ID: 35204

#include<bits/stdc++.h> #define int long long using namespace std; int n, sum[1005]; string a[1005]; map<string,int> ss; signed main() { ss.clear(); cin >> n; for(int iu = 1; iu <= n; iu++) { a[iu].clear(); char op[105], ad[105]; int ans = 0, w = 0, x = 0, y = 0; string sk; sk.clear(); cin >> op; cin >> ad; int kf = 0, knf = 0; for(int i = 0; i < strlen(ad); i++) { if((i == 0 && ad[i] >= '0' && ad[i] <= '9') || ( !(ad[i-1]>= '0' && ad[i-1] <= '9') && (ad[i] >= '0' && ad[i] <= '9'))) kf++; if(knf == 1 && !(ad[i]>='0'&&ad[i]<='9')) { kf = 999; break; } if(ad[i] == ':') knf = 1; } if(kf != 5) { a[iu] += 'E'; continue; } for(int i=0; i<strlen(ad); i++) { if(ad[i]=='.') x++; if(ad[i]==':') y++; if(ad[i] != '.' && ad[i] != ':' && !(ad[i] >= '0' && ad[i] <= '9')) { w = 1; } sk += ad[i]; } if(x != 3 || y != 1 || w == 1) { a[iu] += 'E'; continue; } for(int i=0; i<strlen(ad); i++) { if(ad[i]=='.'||ad[i]==':') { if(ans>=0&&ans<=255) { ans = 0; continue; } else { w = 1; break; } } if(i == 0 || ad[i - 1] == '.' || ad[i - 1] == ':') { if(ad[i] == '0') { if(i == strlen(ad)-1 || ad[i+1] == '.' || ad[i+1] == ':') { ans = 0; continue; } else { w = 1; break; } } } ans = ans * 10 + ad[i] - 48; } if(ans < 0 || ans > 65535 || w == 1) { a[iu] += 'E'; continue; } if(op[0]=='S') { if(ss[sk]>0) { a[iu] += 'F'; } else { ss[sk] =iu; a[iu] += 'O'; } } else { if(ss[sk]>0) { sum[iu] = ss[sk]; } else { a[iu] += 'F'; } } } for(int i=1; i<=n; i++) { if(sum[i]==0) { if(a[i][0]=='E') cout << "ERR"; if(a[i][0]=='F') cout << "FAIL"; if(a[i][0]=='O') cout << "OK"; } else cout << sum[i]; cout << endl; } return 0; }