15分求助!
求助!!!!!!!
#include<bits/stdc++.h>
using namespace std;
int a[65536];
int n;
int ret(string s){
int len = s.length();
long long tmp = 0;
for(int i = 0;i < len;i++){
if(s[i] == '.' || s[i] == ':'){
if(0 <= tmp && tmp <= 255){
tmp = 0;
continue;
}
}
tmp = tmp*10 + s[i]-'0';
}
return tmp;
}
bool check(string s){
int len = s.length();
int flag = 0,fla = 0;
long long tmp = 0;
for(int i = 0;i < len;i++){
if(s[i] == ':') flag += 1;
if(s[i] == '.') fla += 1;
if(s[i] == '.' || s[i] == ':'){
if(0 <= tmp && tmp <= 255){
tmp = 0;
continue;
}
else return false;
}
else if(s[i]<'0'||s[i]>'9') return false;
if(i!=0 && tmp == 0 && s[i-1] == '0') return false;
tmp = tmp*10 + s[i]-'0';
}
if(flag != 1 || fla != 3) return false;
if(0 <= tmp && tmp <= 65535) return true;
else return false;
}
int main(){
cin >> n;
for(int i = 1;i<=n;i++){
string s1,s2;
cin >> s1 >> s2;
if(s1[0] == 'S'){
if(check(s2) == 1){
if(a[ret(s2)] == 0){
a[ret(s2)] = i;
cout << "OK" << endl;
}
else{
cout << "FAIL" << endl;
}
}
else{
cout << "ERR" << endl;
}
}
else{
if(check(s2) == 1){
if(a[ret(s2)] == 0){
cout << "FAIL" << endl;
}
else{
cout << a[ret(s2)] << endl;
}
}
else{
cout << "ERR" << endl;
}
}
}
}