this code is working fine with the custom test cases but not passing even 1 test case in ArrayProblem Section
why??
this code is working fine with the custom test cases but not passing even 1 test case in ArrayProblem Section
why??
hi @dare_devil_007
see for the input
1
2
60 600
the output should be 60600
but your output is coming out to be 60060
if(l1!=l2){
int i(0),j(0);
while(l1!=0 and l2!=0){
int m = a[i++]-'0';
int n = b[j++]-'0';
if(m==n)
continue;
return m>n;
}
return a<b;
}
this logic should just work fine but why it isβnt working?
@dare_devil_007 there is a really simple way to do this
bool compare(string a, string b){
return a+b > b+a;
}
#include<bits/stdc++.h>
using namespace std;
bool compare(string a, string b){
return a+b > b+a;
}
int main() {
int T;
cin >> T;
while(Tβ){
int n;
cin >> n;
string numbers[n];
for(int i=0;i<n;i++){
cin >> numbers[i];
}
sort(numbers,numbers+n,compare);
for(int i=0;i<n;i++) cout<<numbers[i];
cout<<endl;
}
return 0;
}
this code still not passing even one TC