#TEST1012. TCP/IP网络
TCP/IP网络
Background
The protocol is an important protocol in the field of network communication. Your task today is to try to utilize this protocol to restore a simplified network connection scenario.
Topic Description
In this problem, computers are divided into two main categories: Server and Client. Servers are responsible for setting up the network and Clients are responsible for joining the network.
There are a total of computers, numbered , that need to make a network connection, and these machines will initiate a single operation to establish a network or join a network, in increasing order of number.
Each machine is required to provide an address string when attempting to establish or join a network. The address string supplied by a server machine represents the address at which it is attempting to establish a network, and the address string supplied by a client machine represents the address at which it is attempting to join a network.
A conforming address string should have the following characteristics:
- must be of the form
a.b.c.d:e, where are non-negative integers; - , ;
- cannot contain a redundant leading .
Accordingly, an address string that does not conform to the specification may have the following characteristics:
- it is not a string of the form
a.b.c.d:e, e.g., it contains more than characters.or more than characters:, etc. 2. the integers $a, b, c, d:e`; - one or more of the integers is outside the above range;
- one or more of the integers contains a redundant leading .
For example, the address string 192.168.0.255:80 is conformant, but the address strings 192.168.0.999:80, 192.168.02.1:10, 192.168.0.1:088, 192:168:0:1.233, 47.120.30.163:8080:1234, 1..1..1..1:1.233, 47.120.30.163:8080:1234, 1..1..1::1, ... .111111:111111 are all out of specification.
If the address string provided by the server or client when initiating the operation does not conform to the specification, this operation will simply be ignored.
In this problem, we assume that any address string that meets the above specification can participate in a normal connection, and you do not need to consider the actual meaning of each address string.
For reasons such as network blocking, two servers are not allowed to use the same address string, and if this happens, the latter server attempting to establish a network will not be able to do so successfully; otherwise, any server providing an address string that conforms to the specification will be able to establish a network successfully.
If a client providing an address that conforms to the specification provides the same address string as a previous server that has successfully established the network when it tries to join the network, this client can successfully join the network and is said to be connected to this server; if no such server can be found, it is assumed that this client cannot successfully join the network.
Note that while it is not allowed for two different servers to use the same address string, it is allowed for multiple clients to use the same address string, and for the same server to be connected to by multiple clients at the same time.
Your task is simple: given the type of each computer and the address string, determine how connected this computer is.
Input format
First line, a positive integer ().
The next lines, two strings per line, give the type and address string of each computer, numbered from smallest to largest.
Where is guaranteed to be one of the strings Server or Client, and is a string up to in length consisting only of numbers, the characters . and the character :.
The two strings on each line are separated by exactly one space, and there are no extra spaces at the end of each line.
Output format
The output consists of lines, each with a positive integer or string indicating the connection status of the th computer. where:
If the th computer is a server:
- if it provides a canonical address string and successfully establishes the network, output the string
OK. 2. if it provides a canonical address string and successfully establishes the network, output the stringOK. - if it provides an address string that matches the specification, but is unable to successfully establish the network due to a previous server with the same address string, output the string
FAIL. 3. if it provides an address string that matches the specification and successfully establishes the network, output the stringOK. - if it provides an address string that is not a conforming address string, output the string
ERR.
If the th computer is a client:
- if it provides an address string that conforms to the specification and successfully joins the network, output a positive integer indicating the number of the server to which this client is connected.
- output the string
FAILif it provides an address string that matches the specification, but is unable to join the network successfully. 3. - output the string
ERRif it provides an address string that does not conform to the specification.
``input1 5 Server 192.168.1.1:8080 Server 192.168.1.1:8080 Client 192.168.1.1:8080 Client 192.168.1.1:8080 Client 192.168.1.1:99999
```output1
Client 192.168.1.1:80 Client 192.168.1.1:80
Client 192.168.1.1:99999
FAIL
1
FAIL
ERR
ERR
10
Server 192.168.1.1:80
Client 192.168.1.1:80
Client 192.168.1.1:8080
Server 192.168.1.1:80
Server 192.168.1.1:8080
Server 192.168.1.999:0
Client 192.168.1.1.8080
Client 192.168.1.1:8080
Client 192.168.1.1:8080
Client 192.168.1.999:0
Client 192.168.1.1:80 Client 192.168.1.999:0
Client 192.168.1.1:80
1
FAIL
FAIL
FAIL
ERR
ERR
ERR
ERR 5
ERR
Tip.
[Sample Explanation #1]
Computer , a server, provides the canonical address string 192.168.1.1:8080 and successfully establishes a network;
Computer , a server, provides the same address string as computer and fails to successfully establish a network;
Computer , a client, provides the canonical address string 192.168.1.1:8080, successfully joins the network, and connects to server ;
Computer is a client, providing the canonical address string 192.168.1.1:80, and cannot find a server to connect to it;
Computer is a client and provided a non-conforming address string 192.168.1.1:99999.