社区讨论
80pts求条
P7911[CSP-J 2021] 网络连接参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @m2kft25e
- 此快照首次捕获于
- 2024/10/22 20:44 去年
- 此快照最后确认于
- 2024/10/22 21:53 去年
CPP
#include <bits/stdc++.h>
using namespace std;
const int N = 8e3;
int n;
string op, ad;
map<string, int> q;
bool check(string ad)
{
int cnt = 1, f1 = 0, f2 = 0;
long long is = 0;
long long v[90] = {0};
for(int i = 0; i < ad.size(); ++ i)
{
if(ad[i] == '.')
{
++ cnt, ++ f1;
if(f2 != 0 || f1 != cnt - 1 || !is) return false;
is = 0;
}
else if(ad[i] == ':')
{
++ cnt, ++ f2;
if(f1 != 3 || !is) return false;
is = 0;
}
else
{
if(!v[cnt] && ad[i - 1] == '0' && ad[i] != '0') return false;
v[cnt] = v[cnt] * 10 + (ad[i] & 15);
if(v[cnt] > 100000) return false;
++ is;
}
if(f1 > 4 || f2 > 1 || cnt > 5)
{
return false;
}
}
if(f1 != 3 || f2 != 1 || cnt != 5 || !is)
{
return false;
}
for(int i = 1; i <= 4; ++ i)
{
if(v[i] < 0 || v[i] > 255) return false;
}
if(v[5] < 0 || v[5] > 65535) return false;
return true;
}
int main(void)
{
// freopen("P7911_17.in", "r", stdin);
// freopen("t.out", "w", stdout);
cin >> n;
string lst;
for(int i = 1; i <= n; ++ i)
{
cin >> op >> ad;
if(op == "Server")
{
if(!check(ad)) puts("ERR");
else if(q[ad]) puts("FAIL");
else q[ad] = i, puts("OK");
}
else if(op == "Client")
{
if(!check(ad)) puts("ERR");
else if(!q[ad]) puts("FAIL");
else cout << q[ad] << endl;
}
else
{
//puts("LXYCCCCCcdygd");
//return 0;
}
lst = ad;
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...