P7911 60pts求调
  • 板块学术版
  • 楼主ywk2011
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/10/19 21:02
  • 上次更新2024/10/19 22:43:06
查看原帖
P7911 60pts求调
921173
ywk2011楼主2024/10/19 21:02
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 10;
map<string,int> mp;
map<string,int> mp2;
int n;
string str;
char ch[N];
bool flag;
int dou,mao;
bool is255;
int temp;
bool check(){
	for(int i = 1;i<=str.size();i++){
		temp = 0;
		if('0'<=str[i] && str[i]<='9'){
			while('0'<=str[i] && str[i]<='9'){
				temp = temp * 10 + str[i] - '0';
				i++;
			}
		}
		if(str[i] == '.') dou++;
		if(str[i] == ':') mao++;
		if(str[i] == '.' || str[i] == ':'){
			if(str[i+1] == '0' && 0<=str[i+2] && 9>=str[i+2] && str[i+2] != ':' && str[i+2] != '.') return false;
			if(str[i+1] < '0' || str[i+1] > '9') return false;
		}
		if(str[i] == '.'){
			if(str[i+1] == '.' || str[i+1] == ':'){
				return false;
			}
		}
		if(is255 == true){
			if(temp < 0 || temp > 255){
				return false;
			}
		}else{
			if(temp < 0 || temp > 65535){
				return false;
			}
		}
		if(str[i] == ':'){
			is255 = false;
			if(str[i+1] == '.' || str[i+1] == ':'){
				return false;
			}
			if(dou != 3){
				return false;
			} 
		}
	}
	if(mao != 1) return false;
	if(dou != 3) return false;
	return true;
}
signed main(){
	cin>>n;
	for(int i = 1;i<=n;i++){
		cin>>ch;
		getline(cin,str);
		flag = true;
		is255 = true;
		dou = 0;
		mao = 0;
		temp = 0;
		if(check() == false){
			cout<<"ERR"<<endl;
			continue;
		}
		if(ch[0] == 'S'){
			if(mp[str] > 0){
				cout<<"FAIL"<<endl;
			}else{
				cout<<"OK"<<endl;
				mp[str] = i;
			}
		}else{
			if(mp[str] == 0){
				cout<<"FAIL"<<endl;
			}else{
				cout<<mp[str]<<endl;
				mp2[str] = i;
			}
		}
	}
	return 0;
}
2024/10/19 21:02
加载中...