DUP
Time limit2sMemory limit512 MB
Read several pixel matrices, normalize each by rotating it so the plus mark sits at the bottom-left, and list file names that share identical content.
- Level
Medium5 of 10
- Topics
- Matrix, Hash map, Implementation, Sorting
- Solved
- No attempts yet
Problem
A software company started working on a utility program that detects duplicate image files. A simple solution could compare the file name, extension, creation and modification date-time, but the result would not be accurate. To check if two images are duplicates, their content must be compared pixel by pixel.
As a starting point, the company wants to add the ability to compare images of the same size that may be rotated by 90, 180, or 270 degrees. Write a program that takes the image file name and its content as a pixel matrix and lists the duplicate image names.
Input
The first line contains I W H.
- I is the number of input images, I < 1000.
- W is the image width, 0 < W < 100.
- H is the image height, 0 < H < 100.
Each image then starts with:
-
FN is the line containing the file name, len(FN) < 100.
-
Next come W or H lines, each containing W or H characters (pixels).
- Each pixel is represented by a single character (0-9, A-Z, a-z, or +).
- The bottom-left pixel of the original image is marked with the plus [+] sign.
Images are separated by a line of 5 dashes (-).
Output
Print the names of the duplicate images sorted alphabetically in ascending order, one per line.
Hint
The input contains 3 images, each of size 4x3 or 3x4. In the table below each image is rotated back to 0 degrees and then compared.
| Note | Originally the + sign should be at the bottom-left, but the image is rotated by 180 degrees, so it is now at the top-right. | The image is rotated 90 degrees (or -270). | The image is rotated 270 (or -90) degrees. |
| After Rotation | ```
5543
4432
+543
``` | ```
5543
4432
+543
``` | ```
0015
1154
+234
``` |
So [untitled.png, trip2019.png] are duplicates because they have the same content (pixels).