22次csp认证

编程入门 行业动态 更新时间:2024-10-04 01:27:14

22次<a href=https://www.elefans.com/category/jswz/34/1770139.html style=csp认证"/>

22次csp认证

dhcp

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 10010;int n, m, t_def, t_max, t_min;
string h;
struct IP
{int state;  // 0:未分配,1:待分配,2:占用,3:过期int t;  // 过期时间string owner;
}ip[N];void update_ips_state(int tc)
{for (int i = 1; i <= n; i ++ )if (ip[i].t && ip[i].t <= tc){if (ip[i].state == 1){ip[i].state = 0;ip[i].owner = "";ip[i].t = 0;}else{ip[i].state = 3;ip[i].t = 0;}}
}int get_ip_by_owner(string client)
{for (int i = 1; i <= n; i ++ )if (ip[i].owner == client)return i;return 0;
}int get_ip_by_state(int state)
{for (int i = 1; i <= n; i ++ )if (ip[i].state == state)return i;return 0;
}int main()
{cin >> n >> t_def >> t_max >> t_min >> h;cin >> m;while (m -- ){int tc;string client, server, type;int id, te;cin >> tc >> client >> server >> type >> id >> te;if (server != h && server != "*"){if (type != "REQ") continue;}if (type != "DIS" && type != "REQ") continue;if (server == "*" && type != "DIS" || server == h && type == "DIS") continue;update_ips_state(tc);if (type == "DIS"){int k = get_ip_by_owner(client);if (!k) k = get_ip_by_state(0);if (!k) k = get_ip_by_state(3);if (!k) continue;ip[k].state = 1, ip[k].owner = client;if (!te) ip[k].t = tc + t_def;else{int t = te - tc;t = max(t, t_min), t = min(t, t_max);ip[k].t = tc + t;}cout << h << ' ' << client << ' ' << "OFR" << ' ' << k << ' ' << ip[k].t << endl;}else{if (server != h){for (int i = 1; i <= n; i ++ )if (ip[i].owner == client && ip[i].state == 1){ip[i].state = 0;ip[i].owner = "";ip[i].t = 0;}continue;}if (!(id >= 1 && id <= n && ip[id].owner == client))cout << h << ' ' << client << ' ' << "NAK" << ' ' << id << ' ' << 0 << endl;else{ip[id].state = 2;if (!te) ip[id].t = tc + t_def;else{int t = te - tc;t = max(t, t_min), t = min(t, t_max);ip[id].t = tc + t;}cout << h << ' ' << client << ' ' << "ACK" << ' ' << id << ' ' << ip[id].t << endl;}}}return 0;
}

更多推荐

22次csp认证

本文发布于:2024-02-27 23:59:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1767288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:csp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!