求助!只过了13个点,第1,17,18点WA,其它全RE,为虾米啊QAQ
#include<bits/stdc++.h>
using namespace std;
int n,stop,ctop;//stop及ctop指ser及cli的最后位置
struct server
{
string ip;
int num;//此server在输入时的序号
}ser[1010];
struct client
{
string ip;
}cli[1010];
bool check(int kind)//true为有问题,false代表无问题
{ string a;
if(kind==1)
{
a=ser[stop].ip;
}
else
{
a=cli[ctop].ip;
}
if(a.size()>21) return true;//长度超过21直接返回 true
int dian=0,mao=0,dp[5],mp[3];//dp指'.'所在的位置,mp指':'所在位置
for(int i=0;i<a.size();i++)
{
if(dian>3||mao>1) return true;//个数超过了就返回true
if(a[i]<='9'&&a[i]>='0'||a[i]=='.'||a[i]==':')
{
if(a[i]=='.')
{
dian++;
dp[dian]=i;
}
if(a[i]==':')
{
mao++;
mp[mao]=i;
}
}
else//不是1~9或'.'或':' 就返回true
{
return true;
}
}
if(dian!=3&&mao!=1) return true;//小于3就返回
int num=0,x=1;
for(int i=dp[1]-1;i>=0;i--)//把字符串首到第一个'.'的数字取出
{
num+=x*(a[i]-'0');
x*=10;
}
if(num>255) return true;
num=0,x=1;
for(int i=dp[2]-1;i>=dp[1]+1;i--)//把第一个'.'到第二个'.'的数字取出
{
num+=x*(a[i]-'0');
x*=10;
}
if(num>255) return true;
num=0,x=1;
for(int i=dp[3]-1;i>=dp[2]+1;i--)//把第二个'.'到第三个'.'的数字取出
{
num+=x*(a[i]-'0');
x*=10;
}
if(num>255) return true;
num=0,x=1;
for(int i=mp[1]-1;i>=dp[3]+1;i--)//把第三个'.'到第':'的数字取出
{
num+=x*(a[i]-'0');
x*=10;
}
if(num>255) return true;
num=0,x=1;
for(int i=a.size()-1;i>=mp[1]+1;i--)//把第':'到字符串尾的数字取出
{
num+=x*(a[i]-'0');
x*=10;
}
if(num>65535) return true;
return false;//没有问题返回false
}
void tcp(int kind)//kind指类型
{
if(check(kind))
{
cout<<"ERR"<<endl;
if(kind==1) stop--;//向前退一位(因为是err所以没有用 )
else ctop--;
return;
}
if(kind==1)//server
{
for(int i=stop-1;i>=1;i--)
{
if(ser[stop].ip==ser[i].ip)
{
cout<<"FAIL"<<endl;
stop--;
return;
}
}
cout<<"OK"<<endl;
}
else//client
{
for(int i=1;i<=stop;i++)
{
if(cli[ctop].ip==ser[i].ip)
{
cout<<ser[i].num<<endl;
return;
}
}
cout<<"FAIL"<<endl;
return;
}
}
using namespace std;
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
string ip,kind;
cin>>kind>>ip;
if(kind=="Server")
{
stop++;
ser[stop].ip=ip;
ser[stop].num=i;
tcp(1);
}
else
{
ctop++;
cli[ctop].ip=ip;
tcp(0);
}
}
}