洛谷黄题求助
题目:https://www.luogu.com.cn/problem/P7911呜呜呜,我做了半小时,本以为会直接ac,现实给了我一巴掌,55分{:10_266:}
这边两个样例都是正确过了的,我这边没看题解,说一下我的思路,就是写一个函数验证地址是否符合要求,然后呢其他的就在循环里判断,用continue进行下一个的操作,我这代码也真的绝了,一道黄题106行
这边呢只需要提供我的代码错误的地方,不需要你们提供正确的代码,提供代码的绝对是不给最佳答案的,代码长点是因为全是缩进而我没有省略,还是比较好读的,希望大佬积极帮助{:10_254:}
@sfqxx @zhangjinxuan @歌者文明清理员 @liuhongrun2022 来帮我看看{:10_254:}
代码如下:
#include <iostream>
#include <string>
using namespace std;
struct node {
int type;
string ad;
} a;
bool isAdCorrect(string ad) {
int onep = 0;
int twop = 0;
int nlen = 0;
int cnt = 1;
int sum = 0;
for (int i = ad.length() - 1; i >= 0; i--) {
if (ad >= '0' && ad <= '9') {
nlen++;
sum += cnt * (ad - '0');
cnt *= 10;
} else if (ad == '.') {
if (ad == '0' && nlen > 1) {
return false;
}
if (sum > 255) {
return false;
}
if (twop < 1) {
return false;
}
onep++;
nlen = 0;
sum = 0;
cnt = 1;
} else if (ad == ':') {
if (ad == '0' && nlen > 1) {
return false;
}
if (sum > 65535) {
return false;
}
if (onep > 0) {
return false;
}
twop++;
nlen = 0;
sum = 0;
cnt = 1;
} else {
return false;
}
}
if (onep != 3 || twop != 1) {
return false;
}
return true;
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string op;
cin >> op;
if (op == "Server") {
a.type = 0;
cin >> a.ad;
if (!isAdCorrect(a.ad)) {
cout << "ERR" << endl;
continue;
}
bool flag = true;
for (int j = 1; j < i; j++) {
if (a.type == 0 && a.ad == a.ad) {
cout << "FAIL" << endl;
flag = false;
break;
}
}
if (!flag) {
continue;
}
cout << "OK" << endl;
} else if (op == "Client") {
a.type = 1;
cin >> a.ad;
if (!isAdCorrect(a.ad)) {
cout << "ERR" << endl;
continue;
}
bool flag = false;
for (int j = 1; j < i; j++) {
if (a.type == 0 && a.ad == a.ad) {
cout << j << endl;
flag = true;
break;
}
}
if (flag) {
continue;
}
cout << "FAIL" << endl;
} else {
a.type = -1;
cin >> a.ad;
}
}
return 0;
} 这道题目是一个关于IP地址验证和处理的问题。根据您提供的代码,我发现了一些错误和可以改进的地方。
1. 验证IPv4和IPv6格式的错误:
您的代码中有一些验证IPv4和IPv6地址的逻辑,但存在一些错误。对于IPv4地址,每个分段的取值范围应该是0到255,而不是65535。对于IPv6地址,每个分段的取值范围应该是0到65535,而不是255。请注意修正这些取值范围的判断条件。
2. 循环判断逻辑:
在处理输入的IP地址时,您使用了循环,并在其中使用了continue语句。但是,这样的做法可能会导致在一些情况下错过对其他IP地址进行验证的机会。具体来说,当输入的op不是 "Server" 或 "Client" 时,您没有进行IP地址的验证,而是直接将其记录为类型为 -1 的地址。建议您在处理这种情况时也进行地址验证,以保证数据的完整性和正确性。
3. 类型type使用建议:
虽然您在代码中定义了type字段来区分服务器和客户端,但在代码的实际运行中,并没有充分利用这个字段。建议您在验证通过后将类型type和IP地址ad存储在不同的容器中,以便在后续处理中更方便地根据类型进行查找。
4. 函数命名和代码可读性:
函数isAdCorrect的命名并不是很直观,建议将其改为更能反映其作用的名字,例如isValidIP 。此外,代码的可读性也可以进一步改进,可以使用更具描述性的变量名和注释,使得代码更易于理解和维护。
根据上述指点,您可以进行相应的修改和调整,以解决代码中的问题。如果在修改后仍然遇到困难或有其他问题,请随时在 StackOverflow 上继续寻求帮助。祝您成功解决问题! 根据你提供的代码,我注意到有几个问题。首先,在isAdCorrect函数中,你对IP地址进行验证的逻辑存在一些错误。具体来说,你在判断.和:之后的数字是否为0时,条件应该是nlen == 1而不是nlen > 1。此外,在判断四个.和一个:的数量时,你使用的条件是onep != 3 || twop != 1,这将导致即使有多个.或多个:也会被认为是正确的。正确的条件应该是onep == 3 && twop == 1。
除了上述问题,我还注意到在主函数中,你对循环的起始值设置为1,但数组a的索引是从0开始的。因此,你应该将循环的起始值改为0。
综上所述,以下是修正后的代码:
#include <iostream>
#include <string>
using namespace std;
struct node {
int type;
string ad;
} a;
bool isAdCorrect(string ad) {
int onep = 0;
int twop = 0;
int nlen = 0;
int cnt = 1;
int sum = 0;
for (int i = ad.length() - 1; i >= 0; i--) {
if (ad[ i] >= '0' && ad[ i] <= '9') {
nlen++;
sum += cnt * (ad[ i] - '0');
cnt *= 10;
} else if (ad[ i] == '.') {
if (ad == '0' && nlen == 1) {
return false;
}
if (sum > 255) {
return false;
}
if (twop < 1) {
return false;
}
onep++;
nlen = 0;
sum = 0;
cnt = 1;
} else if (ad[ i] == ':') {
if (ad == '0' && nlen == 1) {
return false;
}
if (sum > 65535) {
return false;
}
if (onep > 0) {
return false;
}
twop++;
nlen = 0;
sum = 0;
cnt = 1;
} else {
return false;
}
}
if (onep == 3 && twop == 1) {
return true;
}
return false;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string op;
cin >> op;
if (op == "Server") {
a[ i].type = 0;
cin >> a[ i].ad;
if (!isAdCorrect(a[ i].ad)) {
cout << "ERR" << endl;
continue;
}
bool flag = true;
for (int j = 0; j < i; j++) {
if (a.type == 0 && a.ad == a[ i].ad) {
cout << "FAIL" << endl;
flag = false;
break;
}
}
if (!flag) {
continue;
}
cout << "OK" << endl;
} else if (op == "Client") {
a[ i].type = 1;
cin >> a[ i].ad;
if (!isAdCorrect(a[ i].ad)) {
cout << "ERR" << endl;
continue;
}
bool flag = false;
for (int j = 0; j < i; j++) {
if (a.type == 0 && a.ad == a[ i].ad) {
cout << j + 1 << endl;
flag = true;
break;
}
}
if (flag) {
continue;
}
cout << "FAIL" << endl;
} else {
a[ i].type = -1;
cin >> a[ i].ad;
}
}
return 0;
}
希望这些修改能够解决你的问题。如果还有其他疑问,请随时提问。
如果问题已经解决,请设置最佳答案 懒得专门为上面两位gpt先生回复了,看了一下,都是错的{:10_245:} 这么长的代码好像没人愿意看{:10_245:} {:10_257:}{:10_257:}{:10_257:}一百多行?! Ewan-Ahiouy 发表于 2023-7-29 17:54
一百多行?!
缩进很占代码量,其实还是容易看懂地 好像很简单的鸭子,我先做做看先{:10_256:} Ewan-Ahiouy 发表于 2023-7-29 17:56
好像很简单的鸭子,我先做做看先
{:10_256:} https://www.luogu.com.cn/record/109358197 这题正好是我那年考csp做的 tommyyu 发表于 2023-7-29 18:00
这题正好是我那年考csp做的
就是原题{:10_256:} 算法/非py不要@我 这是其中一个 WA 的输入,我给大家看一下1000
Client 25.71.134.48:30588
Client 25.71.134.48:00588
Client 25.71.134.48:305883
Client 6879287681::07:609027
Server 53.254727.98:62299:
Client 78.130.139.51:51682
Client 1::054833:2.7:
Server 50.193.23.89:46872
Server 100.250.202.27:5224
Server 5.:05:148288.62
Client 26.71.134.48:30588
Client 100.250.202.27:5224
Server 1117139.1580124:94137
Client 199.36.250.121:36597.
Server 119.33.64.7:53367
Server 100.250.202.20:522496
Server 239.93.98.86:6430
Client 25:71.134.48:.0588:
Client 212.112.29.226:561018
Client 43.212.17.131:60012
Client 25.71.134.48:30588.
Server 225.152.143.177:18650
Client 180.51.226.5:26024
Server 139.130.189.162:28130
Server 163.29.48.109:21528
Server :894.52801424175.8923
Client 139.130.189.162:28130
Server 150.194495.187:467591
Client 88.81.154.231:24324
Server 128.109.123.223:33112
Server 171.10.159.85:58713
Client 583033:.69:4
Server 117.255.58.106:37283
Server 88.81.154.231:24324
Server 153.233.179.93:64529
Client 161.79.208.114:18708
Client :197616::.624::12::23
Server 033.23.59.154:45249.
Server 155.220.151.33:148610
Client 143.112.173.29:52878
Server 50.136.0.88:3680
Client 160.121.201.211:2411607
Client 153.233.179.93:645294
Client 94.23.255.111:29533
Server 12.15.67.223:18110
Server 232.109.249.6:4100954.81
Server 106.176.73.43:22009
Server 176.146.170.252:36552
Server 70.13.244.197:4942
Server 31.229.244.222:585274
Client 88.81.158.231:943242.129
Server 126.202.131.61:47527
Server 171.10.159.85:587133
Client 176.146.170.252:36552.
Server 43.93.147.21:53560
Server 187.10.30.61:43553
Client 25.71.134.4893058896
Server 189.253.80.219:6241
Server 59.12.140.227:60602
Server 186.80.226.9:4541
Client 186.80.226.9:4541
Server 154.142.144.79:54464
Client 50.136.0.88:3680
Client 225.152.143.107:1865083
Server 5943818::05:.565222745
Server 220.97.238.53:30899
Server 16.204.88.247:65177
Client 79.130.139.51:516821
Client 110.209.131.22:404675:
Client 12.15.67.223:08110
Server .03.6.54.19::427194
Client 226.28.205.194:27618
Client 186.202.131.61:47527
Client 215.153.156.173:50723
Server 167.246.193.109:19053
Client 189.253.80.219:6241
Client 25.71.134.40:30578
Client 142.181.92.211:14201
Client 208.65.4.178:2681
Client 187.10.30.61:43553
Server 132.42.90.78:15218
Client 2.172.251.149:453991
Server 74.181.17.129:4131
Client :622
Server 173.223.153.245:18188
Client 174.61.29.49:59523
Server 131.191.202.63:52330
Client 158.2.191.253:44049
Server 56.180.138.216:54987
Server 220.122.52.195:51211
Server 170.57.58.71:11621
Server 229.238.132754:28664
Client 74.155.26.70:23577
Client 142..01.92.211:14201
Server 237.90.204.167:34380
Server 136.14.8.14:14404
Client 50.19..23.89:46872
Client 153.233.179.93:64529
Client 237.90.204.477:34380
Client 88.81.154.231.243248
Client 128.109.123.223:33172
Client 220.122.52.195:51211
Server 225.244.38.205:32434
Server :
Client 148.1.1.92.211:14201:
Server 250.709167.123:62431
Server 67.66.123.23:55404
Server 65.12.96.221:48538
Server 32766:1.82::6.29.2.94
Server 4...
Client 154.142.144.79:54464
Server 1101.12.253:58170
Client 1:6.80.226.9:4541
Client 96.98.186.178:23991
Client 150.244.30.159::7009
Client 225.152.143.177:18650
Server 65.17.147.254:171900
Server 24.165.237.104:62182
Server 64.87.25.79:25899
Client 56.180.138.216:549879
Server 86.235.238.181:462056
Client 138.2.191.253:44049
Client 50.136.0.88:36807
Server 44.98.129.156:65334
Server 8:1929
Client 131.191.202.63:52330
Client 128.248.86.117:21531
Server 234.28.105.66:18752
Server 152.177.104.81:4048
Client 220.97.238.53:30899
Client 210.9.30.76:1364
Server 254.2.231.76:32109
Client 74.181.17.129:4131
Client 0.60
Server 113.97.94.210:59051
Server 90.193.151.82:6512
Client 234.28.105.66:18752
Client 167.246.193.109:19053
Server 99.74.83.2:19998
Server 175.105.35.227:63841
Server 25.71.124.48:3058.1
Server 185.186.75.131:32726
Client 173.223.153.245:18188
Server 43.213.192.255:53709
Client 165.140.199.224:1893214
Client 67.66.123.23:55404
Server 174.190.35.96:26926
Client 22.223.146.222:5364
Server 215.204.199.93:8647
Client 207.6.104.14:500831
Client 97.34034.54:70447287
Client 82.211.46.11:48999
Server 226.1.213.10:9691
Client .11855220
Client 142.181.92.211:1420128
Client 125.122.255.102:11451
Server 29.93.96.231:6010
Server 85.179.43.5:41687
Client 24.165.237.104:62182
Server 117.24.40.7.:39234572
Server 155.46.201.117:35081
Server 150.195.223.91:26260
Client 186.80.226.9:45415
Server 29.116.65.63:14998.
Client 210.131.206.245:1751580
Server 59
Server 3.110.47.21:28119
Server 96.98.186.178:23991
Server ..7:35622808817
Server 1:5.4727.88
Server 87.29.77.199:38605.
Server 86.78.212.199:36531
Client 98.121.87.156:5798
Server 154.229.150.177:24886
Client 85.179.43.5:41687
Server 235.188.0.238:36689
Server 115.20.164.98:9867
Server 154.95.104.106:4694
Client 50.136.0.88:36803:
Client 67.66.123.23:55404.
Client 00.193.23.89:468729
Client 67.66.123.27:554042
Client 117.255.58.106:37283
Server 209.140.35.127:54020
Client 43.213.192.255:53709
Client 41.249.207.209:61768
Server 196.119.190.199:4042
Client 56.180.138.216:54987
Client 142.181.92.211:14401
Server 59.235.77.161:40919
Client 1395130.189.162:28130
Server 170.158.33.240:58629
Client 86:5.:43.7.215.61.143.46:
Client 99.74.83.2:19998
Server 66.176.187.75:48347
Client 209.140.35.127:54020
Server 189.85.120.116:61357
Client 215.246.8.96:58255
Client 215.204.199.93:8647
Server 131.150.111.232:41041
Server 231.92.61.232:5637
Client 254.2.231.76:32109
Client 125.122.255.102:11451.
Client 215.204.199.03:86473
Server 254.127.253.180:43706
Client 137.42.90.78:15218
Server .93547:8.1:56:1:3275.
Client 170.158.33.240:58629
Server 152.33.183.117:29397
Client 167.246.193.109:190539
Server 35.40.187.244:27636
Client 163.20.48.109:215282:
Client .87.06
Client 85..79.43.5:416879
Client 225.122:143.177:186507
Client 156.55.108.236:13330
Client 185.186075.131:32726
Server 22.227.99.91:13807
Client 660174.10.31:34966
Client 237.90.204.167:34380
Client 88.204.207.101:28776.
Client 176.146.170.252:36552
Client 35.40.187.244:27636
Server 52.3.107.54032011
Server 162.26.91.29:49723
Client 225.244.38.205:32434
Server 203.175.177.24:29840
Client 126.202.131.61:47527
Client 64.87.25.79:25899
Client 189.253.80.219:62418
Client 12.15.67.223:18110
Client 170.193.68.184:27586
Server 201.107.87.59:36655
Server 114.697.46.138:412417
Server 0.99.75.149:55221
Server 11.21.243.92:251436
Client 153.56.74.224:03494.
Client 135.92.58.220:43797
Server 53.142.90.106:63335
Server 212.133.148.22:30236
Client 226.1.213.10:9691
Server 119.33.64.7:533674
Client 4.6.26885:
Client 167.16.127.50:43445
Server :63.28.484109:215287236
Server 226.28.205.194:27618
Server 166.254.193.84:39225
Server 198.103.214.168:3661605
Server 104.34.205.157:25559
Server 174.247.248.254:290779.
Client 59.12.140.227:60602
Client 65.12.96.221:48538:
Client 166.254.193.84:39225
Client 102.231.1.197:587953
Client 878
Server 140.232.34.181:46657
Client 667:3982199477359333:
Client 115.20.164.98:9867
Server 38.213.242.26:53348
Server :9070.
Server 45.192.177.132:19821
Client 53.142.90.106:63335
Server 59.04049:228:9394:074:937
Client 247.4.131.189:340172
Client 530142.90.106:633359
Client 235.188.0.238:36689
Server 8.592.954:3084:2593
Server 37.43.40.233:269596
Client 186.80.226.9:4.41
Client 8695::2
Server 102.56.242.178:10635
Server 126.10.0.193:9066
Client 126.202.131.61:47527.
Client 248.53.68.1:5932.0
Server 27.62.189.242:49717
Server 125.27.81.241:21973
Client 50.193.23.89:46872
Client 132.181.92.211:142017
Client 154.142.144.79:5446405
Server 82.211.46.11:48999
Server 52.241.37.48:2911
Client .4.155.26.70:2357715
Client 176.155.112.108:30915
Client 93.37.123.123:133353
Client 402
Server 34.47.203.1:17992
Server 26.81.54.49:505060
Client 139.130.189.162:28130:
Client 131.150.111.232:41041
Client 163.29.48.1097215.80
Client 52.241.37.48:2911
Client 29.93.96.231:6010
Server 76.116.150.165:9303
Client .15.246.8.96:58255
Client 876.146.170.252:36552
Server 27728:0676010:58:8467545:
Client 35.40.187.244:07636
Client 5:9739.671130809
Client 119.33.64.7:53367
Server 120.121.8.64:56850
Client 136.14.8.14:14404
Client .73:.1
Server 16.110.230.230:55478
Client 2:8:2::::3
Client ::.7..0:
Client 235.18890.238:36689
Client 148.120.27.202:602.71
Client 16.110.230.230:55478
Server 85.19.216.151:47884
Client 74.181.17.129:613609
Client 245.199.5.143:26642
Server 25.71.134.48:30588
Client 180.510226.5:26028
Server 219.17.253.122:50747
Client 04.4.387::464...61
Server 142.184.92.211:14201
Server 22.223.1461222:5364077
Server 227.232.06.84:76790
Client 88:1839833:..1.:9:51:89
Client 61735.7972..:61:5503.
Client 25.71.134.4::30588
Server 114.186.10.208:1071
Client 155.46.201.117:35081
Server 97.109.41.242:40146
Client 170.158.33.240:596298
Client 126.202.131.61:4752791
Server 3.122.21.143:36823.
Server 174.156.245.113:51034
Server 28.6.198.206:782247
Server 9.35.159.162:30859
Server 145.253.4.199:10770
Client 120.121.8.64:56850
Server 185.2.84.182:17619
Client 99.147.30.56:54505
Client 201.107.87.59:36655
Server 6.120.4.28:35347
Server 169.49.220.128:1666
Server 14.181.108.212:25419
Server 109.191.45.80:28902
Client :
Client 25.71.134848:30588
Server 200.30.164.94:44393
Server 709:.6051:6...218
Server 50.142.132.159:23265
Client 136.66.79.207:55616
Client 191.116.193.34:44469
Server 119.29.170.187:10232
Server 50.193.23.89:46772
Client 152.177.104.81:4048
Client 174.21.236.187:29658
Server 177.247.219.233:42973
Client 30.182.226.37:17892
Server 53.47.164.117:63077
Client 34.235.109.226914146
Server 58.121.139.144:34181
Server 209.51.190.29:17272
Client 143.114.82.59:49369
Server 115.98.198.224:34428
Server 937
Client 288.65.4.178:2691
Server 213.145.138.34:0814
Server 29.151.177.92:58268
Server 143.112.173.29:52878
Server 11
Client 3.110.47.21:281196
Client 174.156.245.113:510349
Client 89.252.102.204:21005
Server 217.94.62.30:10482
Server 42:5..8
Client 25.71.134.48:3058827.
Client 152.177.104.81:4048:9
Client 162.22.219.76:9015
Client 5:.136.0.88:3680
Client 15:.233.179.93:64529::
Server 191.239.3.146:28977
Server 176.46.248.165:278459
Client .17.29.1706187:102320389
Client 50.142.13:.159:232658
Client 212.155.60.25:23383
Server 123.194.66.94:31704
Server 231.170.64.1:41839
Server 28.135.222.106:35683
Client 97.10..41.242:40146
Server 00.51
Client 151.165.138.159:15069
Client 174.190.35.96:26926
Client 87.206.66.253:63865
Client 25.71.034.48:30588
Client 189.85.120.116:61357
Client 118.38.195.814:23815
Server 105.70.147.176:526116
Client 8898:9:6:0:6.:5.732::0
Client 217.172.94.263:18324
Server 211.26.254.204:18700
Server 116.6.77.168:53036
Client 7107.24292:0..:..0
Client 005..690181
Client 56.180.138.216:549877
Server 646..77:458..109386432
Server 203.175.177.24:2984013
Client 115.98.198.224:37428.
Client 84.87.25.79:25899
Client 6734.210:7961288.7:
Client 44.98.129.156:65334
Client 131.150.111.232:410413
Server 129.42.137.48:44896
Server 228.81.172.251:55096
Client 0761:538896:.4
Client 6.120.4.28:35347:
Server 59.12.140.227:606027
Server 53.191.194.56:27503
Client 2
Server 4.74.193.149:31676:
Server 240.148.1708111:6486961
Client 873.223.153.24.:1818.
Client 30.158.236.88:75234
Server .12.239.51.134:489235
Client 27.118.35.134:60665
Server 74.39.102.51:28740
Client 74.39.102.51:28740
Server 131.109.137.159:56095
Server 3.76.79.100:17700
Server 198.146.3.210:45553
Server .3:2277
Server 178.154.182.67:38717
Client 25.71.134.4.:3058834
Client 747.3:644:758.0546455
Client 207.40.144.193:45747
Server 136.32.251.34:17725
Client 128.109.123.223:33112
Server 135.80.53.30:33972
Server :8..343
Client 50.142.132.159:232652
Client 179.184.183.145:.61545
Client 242.22.6.107:258359
Server 71.9.160.156:51035
Client 8.50:6:9:73214692035:
Client 2:.:37325589:19537
Server 90.120.42.158:62778
Server 211.268254.204:187003:
Client 59.168.241.193:62957
Client 0:1:51690650:286071.:4
Server 78.107.94.136:74
Server 88.67.173.121:21069
Client 170.158.33.240:586292
Server 162.198.234.45:9847
Server 72.174.5.196:21886
Client 176.174.97.182:391
Client 220.240.21.195:8116
Server 98.2537193.8:32371
Server 235.86.157.172:3144
Client .4.0438198.0465.3.
Client 245.151.162.54:36594
Server 185.2.84.18::97619
Client 85.19.216.151:47884
Client 34.47.203.1:17992
Server 102.10.43.119:5149
Server 158.157.213.184:26687
Server 50.123.102.47:13234
Client 28.135.222.106:35683
Client 0.42.82.60:33484
Server 160.28.56.11:57168
Server 90.233.162.237:292083
Server 8:.179.43.5:406871
Client 135.80.53.30:33972
Client 00.121742.158:627783
Client 520241.37.:8:2911
Client 176.174.974182:39176
Server 199.234.96.28321732
Client 198.146.3.210:45553
Client 142.181.92.211:14201:
Server 103.220.154.191:25875
Client 45.192.177.132:19821
Client ..96:5448:::..:67951::
Client 22.227.99..1:.3807
Client 948.
Client 108.61.19.93:57850
Client 88.67.173.121:21069
Server 80.51.130.14:31090
Client 213.79.179.131:49363
Server 9
Server .
Server 120.121.8.67:5651067
Server 5.136.186.704:1945465
Server 122.94.54.163:60684
Client 103.220.154.191125875
Client 223.30.97.246:40916
Server 193.94.149.75:63473
Server 466.24
Client 78.1.0.139.51:51682
Client 53.142.90.106:633355
Client .1506
Client 27.62.189.242:49717
Server 9:5.8049747
Client 35..825:5
Client 240.103.85.72:557268
Client 160.28.56.11:5916796
Client 125.54.96.244:2934
Server 250.51.220.92:10047
Server 62183.:.3813642.89:
Client 28.135.222.006:35683
Server 231.145.145.228:3159
Server 239.93.98.86:64309
Client 239.93.98.86:6430
Server 249.106.165.17:36129
Server 166.28.44.62:4.127977
Server 110.27.172.106:11372
Client 86.78.212.199:36531
Server 134.211.758.23:62047
Server 158.253.17.198:7488
Server 238.188.92.113:61766
Server 51.73.184.4:46036
Client 239.93.98.86:64309
Client 167.87.2.159:63918
Client 187.10.30.61:435537
Server 120.120.143.189:19485
Server 107.127.52.11:59912
Client 187.10.30.61:435533
Client 131.191.202.63:52130
Server 13.215.21.229:47919
Server 214.185.185.225:23713
Server 137.116.146.33:31336
Server 195.33.239.35:45202
Server 12.59.253.192:46263
Server 28820.239.67:318214
Server 49.44.170.115:0715
Client 200.30.164.94:44393
Server 7.108.624160:49845
Client 174.190.35.96:268267:8
Server 6659:442.:124464
Client 71.9.160.156:51035
Server 18.102.130.63:417396
Client 174.190.35.96:269268
Client 060886:39:2:1
Client 179.81.62.67:63337
Server 58.102.239.130:25640
Client 054.1.7.253.180:43706
Client 107.127.52.11:59912
Client 108.204.162.221:18203
Server .379154898.1.377:0.2040
Server 89.153.237.79:21445
Server 90.170.110.139:07725
Server 148.11.57.143:13239:
Client 53156:2.130:1536517
Client 64.206.146.224:56932
Server 250.152.7..122:18228
Client 139.148.97.70:16103:
Server 118.243.26.124:14257
Client 247.192.209.75:3288
Server 171.18.179.79:10142
Server 106.20.177.252823980
Client 213.79.179.131:47363
Client 24.165.237.104:621823
Client 27460
Server 128.98.39.32:27776
Client 96.81.97.191:48127
Server 57.249.17.224:32589
Client 1730223.153.245:18188
Server 123.118.107.126:18993
Server 23.118.221.156:2813
Server 201.112.94.39:59817
Server 178.54.86.244:17231
Client 053
Client 58.121.139.144:34181
Client .34.0.22:87745:3.4551:
Server 80.199.65.207:297
Client 116.6.77.168:530368
Server 170.207.122.36:44394
Server 54.142.119.27:540361
Client 129.191.65.145:19470
Client 123.118.107.126:18993
Server 43.216.161.84:46733
Client 176.130.32.62:56504
Client 96.110.230.230:52478
Server 101.196.210.156:192532
Client 177.128.123.174:24409
Client 6.160.31.229:53863
Server 20.223.74.62:4964
Server 37.69.216.19:10513
Client 126.10.0.193:9066
Client 235.86.157.172:3144
Client 82.12.100.145:28532
Server 136.2248993.84:392259324
Server 1:::5501675:4164.5
Client 249.106.165.17:36129
Server 72.76.52.6:51976
Server 170.31.83.158:59479
Client 129.42.137.48:44896
Client 88.67.178.121:21069..
Client 120.121.8.64:568500:
Server 50.136.0.88:368073
Client 3377::.:36...3210:30.4:
Server 128.46.123.148:48259
Client 162.22.219.76:.015
Server 225.179.200.94:27320
Server 87.122.128.132:221941
Server 52.219.121.240:35928
Server 135.174.128.25:15766
Client 153.156.87.39:50224
Client 25.71.134.48:305882:
Client 516931:647
Server 106.209.48.61:6526
Client 254.0.231.76:32109
Client 50.136.0.88:3.80
Server 24.125.11.200:23357
Client 35.40.187.244:27636:3
Client 102.10.43.119:5149
Server 100.30.156.106:45946
Client 144.89.86.212:209588
Client 59.235.77.161:409199
Client 9.914.::36
Server 212.155.60.25:23383
Server :1:677569
Client 75.71.134.48:30588
Client 132.42.90.78:15218
Client 23.118.221.156:28130
Server 205.68.147.239:654859
Server 121.246.210.146:8781
Client 176.130.32.62:5650.
Server 201.107.87.59:36655:
Client 203.175.177.24:29840
Client 191.176.1.237:9821
Server 109.221.146.137:45783
Client 170.158.33.260:58629
Client 121.246.210.146:8781
Client 16.110.230.230:55478.
Client :3.:75741:1:617280:77099.
Server 153.241.123.198:60984
Client 131.109.137.159:56095
Server 19.189.81.223:25355.
Client 29.93.96.231:5010
Server 242.18.211.9:57173
Server 176.104.35.176:25358
Client 02:029.7.893
Client 234.28.105.66:1875295
Server 69.124.145.196:734
Server 70.97.122.220:39380
Client 226.28.2054199:27618
Client 111.87.146.57:30898
Client 231.145.145.228:3159
Client 74515
Server 41.175.193.144:11599
Client 66.188.124.152:21715
Client 137.214.216.161:11748
Client 177.247.219.233:42973
Client 6.120.4.28:35347.
Client 0.99.75.147:553210
Server 84.4.90.156:21203
Server 138.126.136.781:3661:
Client 29.93.96.271:60105
Server 105.110.188.225:48472
Client 27240:23.3
Server 87.206.66.253:63865
Client 107.127.52.11:599125
Client 91.94.66.77:64388
Client 187.173.134.177:14983
Server 213.79.179.131949363
Client 82.12.100.145:2853262
Server 23.137.5.80:28560
Client 109.221.146.137:45783
Server 194.109.233.10:55258
Server 255.107.170.27:3082.
Server 69.185.249.92:58400
Client 177.247.219.233:420739
Server 1.121.109.24:2656
Server 4.83:990:6:6.:5538.
Server 144.45.160.144:63378
Client 220.122..2.195:51218
Server 124.105.163.159:281573
Client 119.47.195.36:353531
Server 206.208.154.222:32986
Server 168.37.218.197:10641
Server 114.58.87.253:15939
Client 120.149.140.224:12514
Client :95.:.35.:2
Server 75.15.73.46:7353
Server 177.128.123.174:24409
Client 79.144.86.001:55740
Client 57.249.17.224:32589
Server 191.79.208.114:18708
Client 196.119.190.199:4042
Client 24.125.11.200:23357
Client 154.229.150.177:24886
Server 133.44.187.205:43446
Server 158.197.248.255:20129
Client 1.3.44.1.7.20::43446
Server 163.185.100.112:297
Client 42.42.121.107:60546
Server 13.55.213.50:51354
Server 68.147.35.143:7
Server 3:31.1444.9416..6
Client 143.112.173.29:5283862
Client .203.61858:2.
Client 237.90.204.167:343804
Client 47.20.43.157:22799
Client 210.135.39.193:14168
Server 30.95.85.139:27008
Server 95.70.64.95:21193
Client 217.94.62.30:10482
Server 238.6.94797:187853
Server 44.171.91.32:26423
Client 125.37.188.194:25753
Server 190.4.180.250:7176
Server 42.207.27.218:57445
Client 176.130.32.62:56904
Server 236.1:0.115.51:311084
Server 125.138.224.112:48625
Server 190.73.121.135:33153
Client 38.213.242.26:53348
Server 184.148.224.221:44045
Server 127.119.167.223:53604
Server 135.125.103.12:9140
Client 220.97.238.53:30899::
Client 227.45.71.82:61708
Client 172.97.1.210:11882
Server 45.44.75.22:5290
Client 0:6.867...82...9:517:
Server 74.39.102.51:28740.
Server 199.230.03.2:2:585889
Server 207.35.2.2.199:576463.
Server 55.249.131.111:60031
Client 237.173.174.231:8661
Server 142.101792.211:742017
Server 202.35.214.8:11146
Server 97.222.186.237:34166
Server 125.27.81.241:2197344
Server 114.47.42.154:32137
Client 234.28.105.66:15752
Client 96.175.12.91:28309
Server 236.105.77.227:45525
Server 26:154:0
Client .2:30:76
Client 953916201.042
Server 113.14.30.135413051
Server 93.115.236.149:34454
Client 3.110.47.21:28119
Server 559:39:9.7256:6.90:
Client .47:35855:..026
Client 117.246.174.247:36311
Client 12059399
Client 31.149.78.191:31817
Server 121.177.147.199:57594
Client 715014..86:.40:.9
Client 225.102.67.83:48243
Server 209.94.60.102:13891
Client 47.196.69.35
Server 56.166.254.72:46573
Client 80.199.65.207:297
Client 3.841:9517331309989:5
Client 295.153.156.173:50723
Server 21.6.173.247:56867
Client 1.121.109.24:26561
Server 81.157.169:38:629595
Client 226.147.174.254:559128
Server 117.45.50.230:29446:
Client 072:844
Server 187.54.168.199:28463.5
Server 66.231.3.90:44
Server 08.60
Server 232.153.111.209:48666
Server 142.110.151.107:28019
Client 252.112.113.94:42535
Client .9.147.9..56:54505166
Server 0.42.82.60:33484
Client 171.10.159.85:58713
Server 26.16.48.165:43611
Server 8.0.58.2
Server 238.236.111.74:63060
Client 85.19.213.151:47884
Client 190.239.3.146:28977
Client 209.140.35.127:54020:
Client 9..1:9.41.042:401463
Client 1326157.117.225:36917::4
Server 49.161.166.5:608669
Client 230.140.1676180:6424691:
Server 59.174.41.44:31671
Client 109.191.45.80:28902
Server 204.177.159.71:53300
Server 162.113.127.220:59217
Server 245.41.2.202:26231
Client 2427852::
Client 13.215.21.229:47919
Server 196.218.139.211:9514
Client 84.4.90.156:21203
Client 64.87725.79:25899
Server 71.73.157.108:1444
Server ..160.31.229:538631
Server 100.70.68.1:32971
Server 255.107.113.217:41996
Server 059:.88
Server 175.83.166.69:22364
Client 186.80.226.9:454147
Server 6.64.183.85:52327
Client 235.188.0.233:9668931
Server 211.211.215.162:17465
Server 21.142.141.2:37240
Client 1.5215.21.229:47919
Server 21..215.64.141:64.02
Server 45.251.62.243:626542
Server 28.14.40.55:41047
Server :::.7..9.87763:37:44301
Client 249.106.165.17:361295
Server 96.175.12.91:283096
Server 102.56.59.200:58169.
Server 87.173.143.169:561519
Client 59.168.241.193:60957200
Client 220.114.38.197:3553
Server 232.16.100.190:30409
Client 6.160.31.229:538635
Server .71:96..:73003205988.2
Client 50.136.0.88:368062
Server 210.67.247.71.42843
Client 125.27.81.241:21973
Client 173..23.153.245:18188
Server 22.245.2.216:31255
Client 108.200.162.221:182030
Server 83:0768:5:53281
Client 116.153.168.71:41810
Server 204.31.106.150:239453
Server 108.211.481220:39235:
Client 76.241.215.229:248396048
Server 80.80.105.192:409622
Client 9035.159.162:308597
Client 153.241.123.198:60984
Client 3.214465256::.3142
Client 189.253680.219:6241.8
Server 48.171.209.75:53
Server .8.8.7:76::2946..0.6:4.6
Client 91.
Client 107.127.52.11:599120
Client 107.44.46.62:151
Client 44.171.91.32:26423
Client 007.127.52.11:59912.
Client 8.:33.716..47.94164.
Client 41.150.234.130:26685
Client 72.174.5.195:2188625.
Server 85.143.254.18:8102
Server 82.12.100.145:2853204
Server 176.104.35.176:253586
Server 42.234.194.251:4860227
Server 10.0.75.23:37674
Client 230.197.90.236:11295
Client 170.57.58.71:11621
Client 8.25.3.17:4294967297
Client :.015.34..
Server 162.238.159.130:246425
Server 225.226.59.85:45434
Server 115.238.77.146:2248
Server 24.7.228.146:10316
Client 35.40.187.244:276364
Client 90.207.21..56:2419688
Client 195.19.213.46:46458
Client 126.202.431.61:47527
Client 114.186.10.208:1071
Server 127.9.249.159:38263
Server 29.68.50.5993131.25
Client 64.87.25.79:208997
Server 9.190.184.238:31389
Client 220.114.38.197:355348
Client 115.20.164.90:9867.3
Server 152.190.49.92:48715
Server 148.78.143.024:19771
Client 106.176.73.43:220093
Client 252.226.206.9:14924
Server 167.155.88.101:55327
Server 807199.65.207:297283
Server 220.114.38.197:35538
Server 164.91.41.48:26883
Client .441128::65962:9873
Client 52.219.121.249:35928
Client 41.175.193.144:11599
Client 80.51.130.14:31090
Server 252.201.43.137:16397
Client 63.0.64.156:51124
Server 93.115.236.149:34454.32
Server ::1663.:4.82827.1
Client 36.61.231.23:26512
Server 2:89569.
Server 105.128.80.86:2360
Client 115.134.72.39:32173
Client 131.191.202063:52330
Client 114.58.87.253:15939
Client 20.71.134.48:30588
Client 162.198.234.40:9847.
Client 49.212.58.13:46378
Server 24.68.132.252:49085
Client 663:.:7:9.16.66
Server 180.48.212.4:9521
Client 69.184.249.22:2840070
Client 95.18.177.183:18738
Client 8.0.110.160:21426
Server 104.167.57.186:568035
Client 171.18.179.79:1014299:
Client 106.10.0.193:9066
Client 615.204.199.93:86470
Client 6.3..1:3.6251
Client 174.61.29.49:590236
Server 250.68.94.174:20025
Server 83.222.214.33:23426
Server 183.200.101.79:4476
Client 11..87.146.57:30898:7
Server 2.116.82.70:34704
Server 40.61.27.123:31946
Client 6.120.4.28.353470.
Client 23.159.168.79:35339
Server 205.191.44.217:329225
Client 89.153.237.79:21445
Client 66.231.3.90:446
Client 107.10.43.119:51491
Client 709.191.45.80:289025
Server 29.125.159.16:6855
Server 245.6.193.29:60271
Client 90.193.151.82:6512
Server 31.36.34.141:65025
Client 51.73.184.4:46036
Client 242.18.211.9:57173
Client 190.127.112.82:1039
Server 165.237.207.153:32826
Server 197.136.109.224:3851
Client 142.110.151.107:28019
Server 83.71.94.236:10407
Server 213.46.136.91:36237
Server 249.243.1:2.182:38635
Server 47.210.162.124:45422
Server 168.204.155.72:116.6
Server 125.19.129.117:27218
Client 097.136:1096224:385107
Client 71.9.16:.156:510358
Server 46.216.181.113:22061
Client :0::996977:575
Server 119.225.192.124:6254
Client 29193.96.231:60105
Server 129.190.133.254:45576
Server 23.15.168.35:23814
Server 115.251.49.169:45896
Server 176.190.202.70:21633
Client .93416:833737713743.7:6
Client 090.218.28.37:49199
Server 47.225.163.234:4457048
Client 21.97.146.216:50872
Server 67.48.108.140:58281.4
Server :39.130.189.162728130.
Server 170.182.78.39:15704
Client 143.112.17..29:5287840:
Client 152.190.49.92:48715
Server 76.131.57.7:53604
Client 212.133.148.22:30236
Client 153.15108.103::020
Client 163.163.247.192:572542
Server 206.13.212.190:41981
Server 298543
Client 99.44.130.86:3205
Server 154.58.161.139:159426
Client 129.190.133.254:45576
Client 167.155.88.101:55327
Server 84.154.217.59:2293014
Server 22.119.14.134:22355
Client 235.167.15..82:45342
Server 133:429.19
Client 230.248.173.231:2064
Client 160.251.212.7:55048
Client 47.210.162.124:45422
Server 4.26.136.126:49780
Client 4.2099.1295:
Client 34.186.202.116:9181
Client 180.51.226.5:26024:
Client 117.255.58.106::7283
Client 38.22.1:.26.:2
Client 123.194.66.94:31704
Client 235.188.09230:36689
Server 54.1.17.41:36257
Server 178.92.104.37:13164
Client 170.202.122.36:4439470
Client 2994:48
Client 44.98.129.156:653340
Server 07.627..665:3738:6:
Client 230.123.143.218:44636
Server 109.221.146.237:45783
Client 3:504..9662532.727924
Server 110.202.237.211:603847
Server 74.155.26.70:23577
Server 161.107.23..31:18.35
Client 76.131.57.7:53644
Client 84.14.140.198:3186
Server 27.246.161.123:31715
Client 1.121.109.24:2656
Server 179.90.115.156:54168:
Client 179.130.189.162:2813075
Client 226.28.200.194:
Client 4:7095.89.:20
Server 142.181.92.211:14201
Server 220.114.38.197:3553
Client 235.188.0.238:366893
Client 174.15..245.113:510349
Server 217.153.81.1:20320
Server :007054:256
Client 196.119.190.199:40426
Client 212.133.148.22:30736
Client ..99.75.149:5522847
Client 910.135.39.1933141680 歌者文明清理员 发表于 2023-7-29 18:05
算法/非py不要@我
这不是算法,模拟和枚举而已{:9_219:} tommyyu 发表于 2023-7-29 18:09
这是其中一个 WA 的输入,我给大家看一下
! 你可以尝试模仿一下我的算法,你想一想,我们使用 sscanf 来格式化读取这个字符串,然后,啊对。
与其在臃肿的代码上删删改改,不如一切重新开始。 zhangjinxuan 发表于 2023-7-29 18:16
你可以尝试模仿一下我的算法,你想一想,我们使用 sscanf 来格式化读取这个字符串,然后,啊对。
与其在 ...
确实。晒一下我的代码{:10_279:}#include<bits/stdc++.h>
using namespace std;
int n;
map<string,int> server;
bool check(string ip)
{
int t={0,-1,-1,-1,-1,-1};
int cnt = sscanf(ip.c_str(),"%d.%d.%d.%d:%d",&t,&t,&t,&t,&t);
if(cnt != 5) return false;
for(int i=1;i<=4;i++)
{
if(t<0 || t>255) return false;
}
if(t<0 || t>65535) return false;
char now;
sprintf(now,"%d.%d.%d.%d:%d",t,t,t,t,t);
if(string(now) != ip)
return false;
return true;
}
int main()
{
cin>>n;
string s,t;
for(int i=1;i<=n;i++)
{
cin>>s>>t;
if(!check(t))//检查ip地址是否合法
{
cout<<"ERR"<<endl;
continue;
}
if(s=="Server"){
if(server==0)
{
server=i;
cout<<"OK"<<endl;
}
else
cout<<"FAIL"<<endl;
}
else
{
if(server>0)
cout<<server<<endl;
else
cout<<"FAIL"<<endl;
}
}
return 0;
}感觉差不多应该是这样 tommyyu 发表于 2023-7-29 18:17
确实。晒一下我的代码感觉差不多应该是这样
对啊,sscanf 简直是一个非常简便的函数{:10_256:} zhangjinxuan 发表于 2023-7-29 18:18
对啊,sscanf 简直是一个非常简便的函数
我认为他可以手动逐行比对一下 14# 和 17#,看一下到底哪里出错了{:10_256:}