Programming contests

20 Programming Exercise for Beginners

January 1, 2019, 12:00 AM – December 31, 2019, 12:00 AM

Linux UNIQ command

On Unix-like operating systems, the uniq command filters out repeated lines. This command does not detect repeated lines unless they are adjacent.

Input Specification

For the sake of simplicity, we suppose that each line consists of at most 2k characters. The number of input lines is not restricted.

Sample Input

  1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  2. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  3. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  4. Aenean ultrices bibendum mollis.
  5. Aenean ultrices bibendum mollis.
download as text file

Output Specification

The output contains the input lines but only once if they are repeated.

Output for Sample Input

  1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  2. Aenean ultrices bibendum mollis.
download as text file

Hints and Guide

Because the length of the input lines are limited, we can easily solve the exercise line by line, reading an input line, for example with the help of the fgets function. You can compare the current line with the previous one by using the strcmp function.

One possible solution is available in: main.c.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 09/30/2024