CSP-J大水题求调(65pts)(大力玄关)

P7911 [CSP-J 2021] 网络连接

额,这样写太复杂了吧
by Po7ed @ 2023-10-08 21:47:39


建议用亿些黑科技
by Po7ed @ 2023-10-08 21:48:13


我的 `check()`: ```cpp bool check(string ad) { int a=0,b=0,c=0,d=0,e=0; char t1=0,t2=0,t3=0,t4=0; sscanf(ad.c_str(),"%d%c%d%c%d%c%d%c%d",&a,&t1,&b,&t2,&c,&t3,&d,&t4,&e); if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535)return 0; if(t1!='.'||t2!='.'||t3!='.'||t4!=':')return 0; stringstream ss; ss<<a<<'.'<<b<<'.'<<c<<'.'<<d<<':'<<e; if(ss.str()!=ad)return 0; return 1; } ```
by Po7ed @ 2023-10-08 21:49:16


@[Po7ed](/user/745171) 什么黑科技
by IDNo1 @ 2023-10-08 21:49:43


@[Po7ed](/user/745171) @[Po7ed](/user/745171) @[Po7ed](/user/745171) WATAHT???
by IDNo1 @ 2023-10-08 21:50:16


大模拟基本上没什么人调( 放一下我的,可以参考一下哪里没有考虑: ```cpp #include <bits/stdc++.h> #define int long long using namespace std; string s[100001], id[100001]; int n; int C(string o, string d, int p) { if (o == "Server") { for (int k = 1; k < p; k++) if (o == s[k] && d == id[k]) return 0; return 1; } else { for (int k = 1; k < p; k++) if (o != s[k] && d == id[k]) return k; return 0; } } bool E(string id) { int p = 0, o = -1, x = 0, sum = 0, l = id.size(); bool flag = 1; for (int i = 0; i < l; i++) if (id[i] == ':') { o = i; break; } if (o == -1) return 0; for (int i = 0; i < o; i++) { if (id[i] >= '0' && id[i] <= '9') { int p = i, x = 0; bool flag = 1; for (int j = i; j < l; j++) { if (id[j] < '0' || id[j] > '9') {i = j; break;} if (flag && id[j] == '0' && id[j + 1] >= '0' && id[j + 1] <= '9') return 0; if (id[j] != '0') flag = 0; x = x * 10 + id[j] - '0'; } if (p == i) return 0; if (x > 255 || x < 0) return 0; sum++; } p += (id[i] == '.'); if (id[i] == '.' && id[i + 1] == '.') return 0; } if (sum != 4) return 0; if (id[o - 1] == '.') return 0; if (o + 1 == l) return 0; for (int i = o + 1; i < l; i++) { if (flag && id[i] == '0' && id[i + 1] >= '0' && id[i + 1] <= '9') return 0; if (id[i] != '0') flag = 0; if (id[i] < '0' || id[i] > '9') return 0; x = x * 10 + id[i] - '0'; if (x > 65535) return 0; } return (p == 3 && x <= 65535 && x >= 0); } signed main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> s[i] >> id[i]; if (s[i] == "Server") { if (!E(id[i])) { cout << "ERR\n"; continue; } if (C(s[i], id[i], i)) cout << "OK" << endl; else cout << "FAIL" << endl; } else { if (!E(id[i])) { cout << "ERR\n"; continue; } if (C(s[i], id[i], i) != 0) cout << C(s[i], id[i], i) << endl; else cout << "FAIL" << endl; } } return 0; } ```
by InversionShadow @ 2023-10-08 21:54:06


@[Po7ed](/user/745171) 为什么我这分代码跑不对 ```cpp #include<bits/stdc++.h> #define re register int using namespace std; int n=114510,c; int main() { string ccf="114514&&&111",b; sscanf(ccf.c_str(),"%d%s%d",&n,&b,&c); cout<<n<<" "<<b<<" "<<c; return 0; } ```
by IDNo1 @ 2023-10-08 21:58:48


@[IDNo1](/user/777131) * IP判断合法时,从IP中提取5个数字,按规则拼接成合法的IP,并于输入的IP比较。 * 使用unordered_map找主机 这是我做题时用的技巧,也顺便总结一下 $Po7ed$
by linnaeuss @ 2023-10-08 21:59:27


@[IDNo1](/user/777131) sscanf 读不了 string
by Po7ed @ 2023-10-09 15:01:09


|