'commit'
This commit is contained in:
48
TangDou/CSP-J/MKX_B/3218.cpp
Normal file
48
TangDou/CSP-J/MKX_B/3218.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
int w[5];
|
||||
bool check(string addr){
|
||||
memset(w, -1, sizeof w);
|
||||
sscanf(addr.c_str(), "%d.%d.%d.%d:%d", &w[0], &w[1], &w[2], &w[3], &w[4]);
|
||||
|
||||
char str[100];
|
||||
sprintf(str, "%d.%d.%d.%d:%d", w[0], w[1], w[2], w[3], w[4]);
|
||||
if (str != addr) return false;
|
||||
for (int i = 0; i < 5; i++){
|
||||
if (w[i] < 0) return false;
|
||||
if (i < 4 && w[i] > 255) return false;
|
||||
if (i == 4 && w[i] > 65535) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int main() {
|
||||
//配置从文本文件读入数据
|
||||
freopen("network.in","r", stdin);
|
||||
freopen("network.out","w", stdout);
|
||||
int n;
|
||||
cin >> n;
|
||||
unordered_map<string, int> hash;
|
||||
for (int i = 1; i <= n; i++){
|
||||
string type, addr;
|
||||
cin >> type >> addr;
|
||||
if(type=="Server"){
|
||||
if(!check(addr))
|
||||
puts("ERR");
|
||||
else if(hash.count(addr))
|
||||
puts("FAIL");
|
||||
else{
|
||||
hash[addr] = i;
|
||||
puts("OK");
|
||||
}
|
||||
}else{
|
||||
if(!check(addr))
|
||||
puts("ERR");
|
||||
else if(!hash.count(addr))
|
||||
puts("FAIL");
|
||||
else
|
||||
cout << hash[addr] << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user