#You are provided an array of numbers.You need to arrange them in a way that yields the largest value

12 messages · Page 1 of 1 (latest)

tall wigeon
#
#include<bits/stdc++.h>
using namespace std;

bool compare(string x,string y){
    return (x>y);
}

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        sort (a,a+n,compare);
        for (int i=0;i<n;i++){
            cout<<a[i];
        }
        cout<<'\n';
    }
    return 0;
}

Ans is correct, yet all testcases fail...

hidden ventureBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

median thicket
#

So given 1,5,4

#

You want "541" ?

tall wigeon
#

Yep

#

Sample input and output

median thicket
#

Okay, ill write something up rq

#

Well

#

This isnt perfect put should work lol

#
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <vector>
#include <string>

using namespace std;

int main() {

    std::vector<int> numbers = { 1, 5, 4, 8, 9, 3, 3 };

    std::vector<int> rearanged;
    for (auto& i : numbers)
    {
        if (rearanged.empty()) {
            rearanged.push_back(i);
            continue;
        }

        int pos = 0;
        for (auto& j : rearanged)
        {
            if (i > j) {
                rearanged.insert(rearanged.begin() + pos , i );
                break;
            }
            ++pos;
        }
    }

    std::string large_number;
    for (auto& i : rearanged)
        large_number.push_back(*(char*)std::to_string(i).c_str());

    printf("%s\n", large_number.c_str());

    return 0xC0000906L;
}```
hidden ventureBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.