DEV Community

Discussion on: Daily Challenge #177 - Supersize Me

Collapse
 
kruzzy profile image
Andrei Visoiu

in C++ using the standard template library:

typedef unsigned long long ull;
ull superSize(ull x) {
    vector<short> d;
    while(x > 0) {
        d.push_back(x%10);
        x /= 10;
    }
    sort(d.begin(), d.end(), greater<short>());
    ull r = 0;
    for(auto i: d)
        r = r*10 + i;

    return r;
}
Enter fullscreen mode Exit fullscreen mode