1 条题解
-
0linjinkun (linjinkun) LV 5 MOD @ 2024-10-04 17:08:34
一道大模拟,没什么好说的。(自己调试就好)
#include<bits/stdc++.h> using namespace std; map<string,int>mp; signed main() { int _; scanf("%d",&_); for(int __ = 1;__<=_;__++) { string s; string ss; cin >> s >> ss; int qq = 0; if(s == "Server") { int i; int a = 0,b = 0,c = 0,d = 0,e = 0; int numa = 0,numb = 0,numc = 0,numd = 0,nume = 0; int xa = 1; int num = 0; bool flag = 0; for(i = 0;ss[i]!='.'&&i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xa = -1; numa++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } numa++; a = a*10+ss[i]-'0'; } a*=xa; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(a).size()!=numa||ss[i+1]<'0'||ss[i+1]>'9') { printf("ERR\n"); } else { int xb = 1; int num = 0; bool flag = 0; qq = 0; i++; for(;ss[i]!='.'&&i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xb = -1; numb++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } numb++; b = b*10+ss[i]-'0'; } b*=xb; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(b).size()!=numb||ss[i+1]<'0'||ss[i+1]>'9') { printf("ERR\n"); } else { int xc = 1; int num = 0; i++; bool flag = 0; qq = 0; for(;ss[i]!='.'&&i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xc = -1; numc++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } numc++; c = c*10+ss[i]-'0'; } c*=xc; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(c).size()!=numc||ss[i+1]<'0'||ss[i+1]>'9') { printf("ERR\n"); } else { qq = 0; i++; bool flag = 0; int xd = 1; int num = 0; for(;ss[i]!=':'&&i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xd = -1; numd++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } numd++; d = d*10+ss[i]-'0'; } d*=xd; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(d).size()!=numd||ss[i+1]<'0'||ss[i+1]>'9') { printf("ERR\n"); } else { qq = 0; i++; bool flag = 0; int xe = 1; int num = 0; for(;i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xe = -1; nume++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } nume++; e = e*10+ss[i]-'0'; } e*=xe; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(e).size()!=nume) { printf("ERR\n"); } else { if(a>255||a<0||b>255||b<0||c>255||c<0||d>255||d<0||e<0||e>65535) { printf("ERR\n"); } else { if(mp.find(ss) == mp.end()) { mp[ss] = __; printf("OK\n"); } else { printf("FAIL\n"); } } } } } } } } } } } } } else { int i; int a = 0,b = 0,c = 0,d = 0,e = 0; int numa = 0,numb = 0,numc = 0,numd = 0,nume = 0; int xa = 1; int num = 0; qq = 0; bool flag = 0; for(i = 0;ss[i]!='.'&&i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xa = -1; numa++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } numa++; a = a*10+ss[i]-'0'; } a*=xa; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(a).size()!=numa||ss[i+1]<'0'||ss[i+1]>'9') { printf("ERR\n"); } else { qq = 0; int xb = 1; int num = 0; bool flag = 0; i++; for(;ss[i]!='.'&&i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xb = -1; numb++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } numb++; b = b*10+ss[i]-'0'; } b*=xb; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(b).size()!=numb||ss[i+1]<'0'||ss[i+1]>'9') { printf("ERR\n"); } else { qq = 0; int xc = 1; int num = 0; i++; bool flag = 0; for(;ss[i]!='.'&&i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xc = -1; numc++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } numc++; c = c*10+ss[i]-'0'; } c*=xc; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(c).size()!=numc||ss[i+1]<'0'||ss[i+1]>'9') { printf("ERR\n"); } else { qq = 0; i++; bool flag = 0; int xd = 1; int num = 0; for(;ss[i]!=':'&&i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xd = -1; numd++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } numd++; d = d*10+ss[i]-'0'; } d*=xd; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(d).size()!=numd||ss[i+1]<'0'||ss[i+1]>'9') { printf("ERR\n"); } else { qq = 0; i++; bool flag = 0; int xe = 1; int num = 0; for(;i<ss.size();i++) { qq++; if(ss[i] == '-'&&!num) { num++; xe = -1; nume++; continue; } if(ss[i]<'0'||ss[i]>'9') { flag = 1; break; } nume++; e = e*10+ss[i]-'0'; } e*=xe; if(flag||qq == 0) { printf("ERR\n"); } else { if(to_string(e).size()!=nume) { printf("ERR\n"); } else { if(a>255||a<0||b>255||b<0||c>255||c<0||d>255||d<0||e<0||e>65535) { printf("ERR\n"); } else { if(mp.find(ss)!=mp.end()) { printf("%d\n",mp[ss]); } else { printf("FAIL\n"); } } } } } } } } } } } } } } return 0; }
- 1
信息
- ID
- 1013
- 难度
- 2
- 分类
- (无)
- 标签
- 递交数
- 2
- 已通过
- 2
- 通过率
- 100%
- 上传者