There is a template function unique()
in STL (Standard Template Library), which takes two iterators \(begin, end\) as parameters, removes all except the first element from every consecutive group of equal elements in the left-closed-right-open range hold by the two iterators \([begin, end)\) and return the iterator to the new end, i.e., the next of the last element not removed.
For instance, in the first of the sample input, since \(k=1\), it's equivlent to the ordinary unique()
. So for the string "qqq", you should return the itrerator next to the first 'q'.
And in this problem, your task is to extend this feature more generally, i.e., remove all excpet the first \(k\) elements from every consecutive group.
You should do it in place, returning valid iterator between origin range. Try to use constant extra space only.
If you want to run the code locally, you have to name your implementation Main.cpp. For more detail, please read instructions in the header.
Since this problem is judged partially, you needn't be concerned about the format of input.
In case your're interested, there are several test cases, each of which contain four lines: the first line is two integers \(n, k\) and the following lines are a sring, \(n\) intergers and \(n\) floating point numbers.
\[0<n<10^6\]
\[0<k\leq n\]
Since this problem is judged partially, you needn't be concerned about the format of output.
In case your're interested, for each test case, the judge code would print out the result after calling k_unique()
for the sting, integers and floating point numbers.