When I check the output for the SAMPLE TEST CASE PROVIDE I CAN SEE THE CORRECT ANSWER BUT IT FAILS ALL THE TEST CASES WHEN I SUBMIT IT.
link:https://ide.codingblocks.com/s/186845
Code gives wrong answer
@vmanav I would recommend you to use strings for solving this problem and use comparator for finding the maximum of both the number after checking both the cases.
@vmanav Your code fails this case
5
90 9 990 889 9.
Try rectifying this case and you will get this accepted
Okay i will try that…
If i open the editorial and then submit the code does a green tick appear on the CHALLENGE…?
@vmanav You can take this code as a reference
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vll vector
#define vpll vector<pair<ll ,ll > >
#define pb push_back
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define fst first
#define scd second
#define fr(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define fr1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define frr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define frab(i,a,b,c) for(ll (i) = a ; (i) < (b) ; (i)+=©)
#define print(v) for( auto it: v) cout<<it<<" ";
#define mst(A) memset( (A) , 0 , sizeof(A) );
using namespace std;
ll A[300005];
bool compa(ll &a, ll &b){
string s1= to_string(a);
string s2= to_string(b);
return (s1+s2>=s2+s1);
return (s1+s2<s2+s1);
}
int main()
{
ll n,t,m,a,b,c,d;
t=1;
cin>>t;
while(t–){
cin>>n;
string s[n];
fr(i,n) cin>>A[i];
sort(A,A+n , compa);
string ans="";
fr(i,n){
ans+= to_string(A[i]);
}
cout<<ans<<endl;
}
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
Some problem with the link you have given to rate experience it says “This page could not be found”.