code crux:
using pair<int,int>
making every element’s length equivalent to length of maximum element by multiplying it by 10 and storing it’s value in pair.second to further sort on that basis.
problem:
getting correct output in custom cases but not getting the mistake that none of my testcase is correct.
#include
#include
using namespace std;
int length(pair<int,int> num)
{
int count=0;
while(num.first!=0)
{
num.first=num.first/10;
count++;
}
return count;
}
bool compare(pair<int,int>a,pair<int,int>b)
{
return a.second>b.second;
}
int main() {
int t;
cin>>t;
while(t)
{
int m;
cin>>m;
int a[100000];
pair <int,int> p[100000];
for(int i=0;i<m;i++)
{
cin>>a[i];
p[i].first=a[i];
p[i].second=a[i];
}
pair<int,int> max;
int *k;
k= max_element(a,a+m);
max.first=(*k);
max.second=max.first;
int len=length(max);
for(int i=0;i<m;i++)
{
int temp=length(p[i]);
if(temp<len)
{
int mul=len-temp;
while(mul)
{
p[i].second*=10;
mul--;
}
}
}
sort(p,p+m,compare);
for(int i=0;i<m;i++)
{
cout<<p[i].first;
}
cout<<endl;
t--;
}
return 0;
}