Lesson 11 of 24

STL Algorithms: sort, reverse, findSTL Algorithms: sort, reverse and find

10 min 30 XP

<algorithm>-ல் தயாரான algorithms: sort, reverse, max_element, min_element, count, find, binary_search. <numeric>-ல் accumulate. ஒரு வரியில் பெரிய வேலை!

<algorithm> gives you ready-made sort, reverse, max_element, min_element, count, find and binary_search; <numeric> adds accumulate. One line, lots of work done.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

sort() சராசரியாக O(n log n). binary_search sorted vector-ல் மட்டுமே சரியாக வேலை செய்யும்.

sort() runs in O(n log n). binary_search only works on a sorted range.

Challenge

+30 XP

n மற்றும் n எண்களைப் படித்து, இரண்டு முறைக்கு மேல் வரும் எண்களை நீக்கி (unique), ஏறு வரிசையில் print செய்யுங்கள்; பிறகு அடுத்த வரியில் வேறுபட்ட எண்களின் எண்ணிக்கை. Input: 7 4 1 4 2 1 9 2 Output: 1 2 4 9 4

Read n and n numbers. Print the distinct values in ascending order, then on the next line how many distinct values there are. Input: 7 4 1 4 2 1 9 2 Output: 1 2 4 9 4

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.