VerkadaOA #1
Find Valid IP Addresses
Estimated EasyJudge-ready
Topics (AI-labelled)Strings
Recursively scan the whitespace-separated tokens in files under root, collect valid IPv4 addresses, and sort them lexicographically, keeping duplicates.
The standard input/output format and supplementary bounds on this site are as stated in this problem.
Input
The first line is the root path; the second line is the number of files f (≤2×10^5); each following line is path<TAB>content, where path is an absolute POSIX path, file contents contain no tabs, and the total number of characters is ≤10^6.
Output
One address per line; if there are no results, output nothing.
Example 1
Input:
/var/log
3
/var/log/a client 10.1.1.1 backup 256.1.1.1
/var/log/sub/b 192.168.0.1 01.2.3.4
/tmp/x 8.8.8.8
Output:
10.1.1.1
192.168.0.1
Example 2
Input:
/data
1
/database/a 1.1.1.1
Output:
Example 3
Input:
/data
7
/database/no ip 1.2.3.4 bad 01.2.3.4
/database/no 255.255.255.255 256.0.0.1
/data/sub/b ip 1.2.3.4 bad 01.2.3.4
/data/a ip 1.2.3.4 bad 01.2.3.4
/data/a repeat 1.1.1.1 1.1.1.1
/data/sub/b 255.255.255.255 256.0.0.1
/database/no repeat 1.1.1.1 1.1.1.1
Output:
1.1.1.1
1.1.1.1
1.2.3.4
1.2.3.4
255.255.255.255
Editorial
Loading solution…