#define int long long后在强转字符报错
查看原帖
#define int long long后在强转字符报错
590596
Gnasvl楼主2023/10/1 22:00

题目

为什么会编译报错?

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
map<string,int> opt;
string op,ad;
bool check(string s){
	int num[6]={0},f=0;
	if(s.length()>25){
		//cout<<1<<endl;
		return 0;
	}
	stack<int> que;
	for(int i=0,o=1;i<s.length();i++){
		if(o>=6) return 0;
		if(s[i]==':'&&o!=4){
		//	cout<<2<<endl;
			return 0;
		}
		if(s[i]=='.'&&o>3){
			return 0;
		}
		if(s[i]==':'&&o<4){
			return 0;
		}
		if(f>4) return 0;
		if(s[i]=='.'||s[i]==':'){
			int bit1=1;
			while(!que.empty()){
		//		if(o==4){
		//			cout<<que.top()<<" "<<num[o]<<" "<<bit1<<endl;
		//		}
				num[o]+=que.top()*bit1;
				bit1*=10;
				que.pop();
			}
			o++;
			f=0;
			continue;
		}
		if(s[i]>='0'&&s[i]<='9'){
			if(f==0&&s[i]=='0'&&s[i+1]>='0'&&s[i+1]<='9'){
				return 0;
			}
			que.push(int(s[i]-'0'));
			f++;
		}
	}
	int bit1=1;
	while(!que.empty()){
		num[5]+=que.top()*bit1;
		bit1*=10;
		que.pop();
	}
	//for(int i=1;i<=5;i++){
	//	cout<<num[i]<<" "<<i<<endl;
	//}
	for(int i=1;i<=4;i++){
		if(num[i]<0||num[i]>255){
	//		cout<<3<<endl;
			return 0;
		}
	}
	if(num[5]<0||num[5]>65536){
	//	cout<<4<<endl;
		return 0;
	}
	return 1;
}
signed main(){
	freopen("P7911_13.in","r",stdin);
	freopen("P7911_13.output","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>op>>ad;
		if(!check(ad)){
			cout<<"ERR\n"; 
			continue;
		}
		if(op=="Server"){
			if(opt[ad]){
				cout<<"FAIL\n";
			}
			else{
				cout<<"OK\n";
				opt[ad]=i;
			}
		}
		else if(op=="Client"){
			if(opt[ad]){
				cout<<opt[ad]<<endl;
			}
			else{
				cout<<"FAIL\n";
			}
		}
	}
	return 0;
}
2023/10/1 22:00
加载中...