1 条题解
-
0Guest LV 0 MOD
-
0
模拟。
#include<iostream> #include<string> #include<map> using namespace std; long long zh(string s) { long long ans=0,sum=1; int n=(int)s.size(); for(int i=n-1;i>=0;i--) { ans+=sum*(s[i]-'0'); sum*=10; } return ans; } bool tf(string s) { int n=(int)s.size(),x1=0,x2 = 0; for (int i=0;i<n;i++) { if(s[i]=='.') { x1++; continue; } if(s[i]==':') { x2++; continue; } if(s[i]<'0'||s[i]>'9') return false; } if(x1!=3||x2!=1) return false; int sum1[4], k = 0; for (int i=0;i<n;i++) { if(s[i]==':'&&k!=3) return false; if(s[i]=='.'||s[i]==':') sum1[k++]=i; } for (int i=0;i<3;i++) if(sum1[i]+1==sum1[i+1]) return false; long long a=zh(s.substr(0,sum1[0])); long long b=zh(s.substr(sum1[0]+1,sum1[1]-sum1[0]-1)); long long c=zh(s.substr(sum1[1]+1,sum1[2]-sum1[1]-1)); long long d=zh(s.substr(sum1[2]+1,sum1[3]-sum1[2]-1)); long long e=zh(s.substr(sum1[3]+1,n-1-sum1[3])); if(a>255||b>255||c>255||d>255||e>65535) return false; if((a!=0&&s[0]=='0')||(b!=0&&s[sum1[0]+1]=='0')||(c!=0&&s[sum1[1]+1]=='0')||(d!=0&&s[sum1[2]+1]=='0')||(e!=0&&s[sum1[3]+1]=='0')) return false; return true; } map<string, int> m; int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i=1;i<=n;i++) { string s1,s2; cin>>s1>>s2; if(tf(s2)==false) { cout<<"ERR\n"; continue; } if(s1[0]=='S') { if(m.count(s2)) cout<<"FAIL"<<endl; else{ m.insert(map<string, int> :: value_type(s2, i)); cout<<"OK"<<endl; } } else{ if(m.count(s2)) cout<<m[s2]<<endl; else cout<<"FAIL\n"; } } return 0; }
- 1