Module: Using set


Problem

3/10

Using set with a comparator

Theory Click to read/hide

Using set with a comparator
An example of a comparator to create an ordered set in descending order. struct cmp { bool operator() ( int a, int b) const{ return a > b; } };
Using a comparator when creating a set. set <int, cmp> s;

Problem

Complete the program with a comparator to solve the following problem.

Given N natural numbers. Output the set sorted by the sum of the digits of the number.
 
Examples
# Input Output
1 4
123 321 34 23
23 123 34