帮忙判断一下pand错哪里了?
查看原帖
帮忙判断一下pand错哪里了?
289056
北射天狼楼主2021/11/7 12:32
#include <bits/stdc++.h>
using namespace std;
int n,num;
string a,s;
int t;
map<string,int>book;
bool pand(string s){
	int l=0;
	for (int i=1;i<=4;i++){
	    num=0;
	    if (s[l]=='0'&&(s[l+1]>='0'&&s[l+1]<='9'))  {
	    	//cout<<"#"<<endl;
		    return true;
	    }
	    while (s[l]>='0'&&s[l]<='9'){
		    num=num*10+s[l]-'0';
		    l++;
		    //cout<<num<<endl;
	    }
	    if (num>255||num<0)    return true;
	    if (i!=4&&s[l]!='.')    {
	    	//cout<<"*"<<endl;
		    return true;
		}
	    l++;
	}
	if (s[l-1]!=':')    return true;
	if (s[l]=='0'&&(s[l+1]>='0'&&s[l+1]<='9'))  {
	    	//cout<<"#"<<endl;
		    return true;
	}
	num=0;
	for (int i=l;i<s.size();i++){
		if (s[i]>'9'||s[i]<'0')    return true;
		num=num*10+s[i]-'0';
	}
	if (num>=0&&num<65536)    return false;
	return true;
}
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a>>s;
		++t;
		if (pand(s)){
			cout<<"ERR"<<endl;
		} else if (a[0]=='S'){
			if (book[s])    cout<<"FAIL"<<endl;
			else{
				book[s]=t;
				cout<<"OK"<<endl; 
			}
		} else if (a[0]=='C'){
			if (!book[s])    cout<<"FAIL"<<endl;
			else cout<<book[s]<<endl;
		} 
	}
	return 0;
}

主函数没有问题!

就是pand函数出现了一点问题,但我没有发现。

65pts

求帮助……

2021/11/7 12:32
加载中...