5 条题解

  • 2
    @ 2023-9-5 20:32:05

    放心食用

    #include <bits/stdc++.h>
    using namespace std;
    int n;
    string x,y;
    map<string,int> mp;
    bool check(string s)
    {
    	int a,b,c,d,e;
    	if(sscanf(s.c_str(),"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e)!=5)
    		return false;
    	if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535)
    		return false;
    	stringstream ss;
    	ss<<a<<"."<<b<<"."<<c<<"."<<d<<":"<<e;
    	if(ss.str()==s)
    		return true;
    	else
    		return false;
    }
    int main()
    {
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>x>>y;
    		if(x=="Server")
    		{
    			if(check(y))
    			{
    				if(mp.count(y))
    					cout<<"FAIL"<<endl;
    				else
    				{
    					mp[y]=i;
    					cout<<"OK"<<endl;
    				}
    			}
    			else
    				cout<<"ERR"<<endl;
    		}
    		else
    		{
    			if(check(y))
    			{
    				if(mp.count(y))
    					cout<<mp[y]<<endl;
    				else
    					cout<<"FAIL"<<endl;
    			}
    			else
    				cout<<"ERR"<<endl;
    		}
    	}
    	return 0;
    }
    
    • 0
      @ 2023-8-24 20:53:39

      没人发题解?👀️ 我来 AC过,放心食用 就是有点长😄 问题不大 有用点赞👍 ,谢谢

      #include <bits/stdc++.h>
      using namespace std;  
      #define LL long long
      #define P pair<string,int>
      string f,s;
      P t[1010]; 
      int n;
      bool judge()
      {
      	int l=s.length(),n2=-1,ff=0,h1=0,h2=0;
      	for(int i=0;i<l;i++)
      	{
      		if(s[i]>='0'&&s[i]<='9')
      		{
      			if(ff)return false;
      			if(s[i]=='0')
      			{
      				if(n2==-1)ff=1;
      			}
      			if(n2==-1)n2=0;
      			n2=n2*10+s[i]-'0';
      			if(h2==0&&n2>255)return false;
      			if(h2&&n2>65535)return false;
      		}
      		else if(s[i]=='.'||s[i]==':')
      		{
      			ff=0;
      			if(s[i]=='.')h1++;		
      			else 
      			{
      				if(h1!=3)return false;
      				h2++;
      			}
      			if(n2<0||n2>255)return false;
      			n2=-1;
      		}
      		else return false;
      	}
      	if(h1!=3||h2!=1)return false;
      	if(n2<0||n2>65535)return false;
      	return true;
      }
      int main()
      {
      	scanf("%d",&n);
      	char ss[100];
      	int ll=1;
      	for(int y=1;y<=n;y++)
      	{
      		scanf("%s",ss);f=ss;
      		scanf("%s",ss);s=ss;
      		if(!judge())printf("ERR\n");
      		else
      		{
      			if(f[0]=='C')
      			{
      				int flag=0,i=1;
      				for(;i<ll;i++)
      				{
      					if(t[i].first==s)
      					{
      						flag=1;
      						break;
      					}
      				}
      				if(flag)printf("%d\n",t[i].second);
      				else printf("FAIL\n");
      			}
      			else
      			{
      				int flag=1;
      				for(int i=1;i<ll;i++)
      				{
      					if(t[i].first==s)
      					{
      						flag=0;
      						break;
      					}
      				}
      				if(flag)
      				{
      					t[ll].first=s;
      					t[ll].second=y;
      					ll++;
      					printf("OK\n");
      				}
      				else printf("FAIL\n");
      			}
      		}
      	}
      	return 0;
      }
      
      • -1
        @ 2023-9-17 12:23:04

        好吃吗

        #include
        using namespace std;
        int n;
        string x,y;
        map<string,int> mp;
        bool check(string s)
        {
        	int a,b,c,d,e;
        	if(sscanf(s.c_str(),"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e)!=5)
        		return false;
        	if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535)
        		return false;
        	stringstream ss;
        	ss<<a<<"."<<b<<"."<<c<<"."<<d<<":"<<e;
        	if(ss.str()==s)
        		return true;
        	else
        		return false;
        }
        int main()
        {
        	cin>>n;
        	for(int i=1;i<=n;i++)
        	{
        		cin>>x>>y;
        		if(x=="Server")
        		{
        			if(check(y))
        			{
        				if(mp.count(y))
        					cout<<"FAIL"<<endl;
        				else
        				{
        					mp[y]=i;
        					cout<<"OK"<<endl;
        				}
        			}
        			else
        				cout<<"ERR"<<endl;
        		}
        		else
        		{
        			if(check(y))
        			{
        				if(mp.count(y))
        					cout<<mp[y]<<endl;
        				else
        					cout<<"FAIL"<<endl;
        			}
        			else
        				cout<<"ERR"<<endl;
        		}
        	}
        	return 0;
        }
        `
        
        • -1
          @ 2023-9-17 12:21:41
          using namespace std;
          int n;
          string x,y;
          map<string,int> mp;
          bool check(string s)
          {
          	int a,b,c,d,e;
          	if(sscanf(s.c_str(),"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e)!=5)
          		return false;
          	if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535)
          		return false;
          	stringstream ss;
          	ss<<a<<"."<<b<<"."<<c<<"."<<d<<":"<<e;
          	if(ss.str()==s)
          		return true;
          	else
          		return false;
          }
          int main()
          {
          	cin>>n;
          	for(int i=1;i<=n;i++)
          	{
          		cin>>x>>y;
          		if(x=="Server")
          		{
          			if(check(y))
          			{
          				if(mp.count(y))
          					cout<<"FAIL"<<endl;
          				else
          				{
          					mp[y]=i;
          					cout<<"OK"<<endl;
          				}
          			}
          			else
          				cout<<"ERR"<<endl;
          		}
          		else
          		{
          			if(check(y))
          			{
          				if(mp.count(y))
          					cout<<mp[y]<<endl;
          				else
          					cout<<"FAIL"<<endl;
          			}
          			else
          				cout<<"ERR"<<endl;
          		}
          	}
          	return 0;
          }
          
          
          • -2
            @ 2023-9-17 12:22:21
            #include
            using namespace std;
            int n;
            string x,y;
            map<string,int> mp;
            bool check(string s)
            {
            	int a,b,c,d,e;
            	if(sscanf(s.c_str(),"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e)!=5)
            		return false;
            	if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535)
            		return false;
            	stringstream ss;
            	ss<<a<<"."<<b<<"."<<c<<"."<<d<<":"<<e;
            	if(ss.str()==s)
            		return true;
            	else
            		return false;
            }
            int main()
            {
            	cin>>n;
            	for(int i=1;i<=n;i++)
            	{
            		cin>>x>>y;
            		if(x=="Server")
            		{
            			if(check(y))
            			{
            				if(mp.count(y))
            					cout<<"FAIL"<<endl;
            				else
            				{
            					mp[y]=i;
            					cout<<"OK"<<endl;
            				}
            			}
            			else
            				cout<<"ERR"<<endl;
            		}
            		else
            		{
            			if(check(y))
            			{
            				if(mp.count(y))
            					cout<<mp[y]<<endl;
            				else
            					cout<<"FAIL"<<endl;
            			}
            			else
            				cout<<"ERR"<<endl;
            		}
            	}
            	return 0;
            }
            
            • 1

            [普及~提高][CSP-J 2021] 网络连接

            信息

            ID
            1356
            时间
            1000ms
            内存
            256MiB
            难度
            4
            标签
            递交数
            299
            已通过
            131
            上传者