1 条题解
-
1
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int n,cnt; struct wifi { string s; int id; } p[1005]; int find(string ad) { for (int i = 1;i <= cnt;i++) { if (p[i].s == ad) return p[i].id; } return -1; } bool chk(string ad) { int cnt1 = 0,cnt2 = 0; for (int i = 0;i < ad.size();i++) { if (ad[i] == '.') cnt1++; else if (ad[i] == ':') { cnt2++; if (cnt1 < 3) return false; } else if (ad[i] < '0' | ad[i] > '9') return false; } if (cnt1 != 3 || cnt2 != 1) return false; if (ad[((int)(ad.size())) - 1] == ':') return false; int j = 0; for (int i = 1;i <= 5;i++) { if (ad[j] == '.' || ad[j] == ':') return false; if (ad[j] == '0' && '0' <= ad[j+1] && ad[j+1] <= '9') return false; long long num = 0; while(j < ad.size() && '0' <= ad[j] && ad[j] <= '9') { num = num * 10 + (ad[j] - '0'); j++; } if (i <= 4 && num > 255 || num > 65535) return false; j++; } return true; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1;i <= n;i++) { string op,ad; cin >> op >> ad; if (!chk(ad)) { cout << "ERR\n"; continue; } if (op == "Server") { if (find(ad) != -1) { cout << "FAIL\n"; } else { cout << "OK\n"; p[++cnt] = {ad,i}; } } else { int id = find(ad); if (id != -1) cout << id << "\n"; else cout << "FAIL\n"; } } return 0; }
- 1
信息
- ID
- 49
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 5
- 标签
- 递交数
- 2
- 已通过
- 1
- 上传者