I have solved this question, and getting the correct answer for almost all the test cases what u could think of. But still the code is not being accepted and shows wrong answer. Can anyone look int the code and tell me where have i committed the mistake.
Link: https://ide.codingblocks.com/s/86566
#include
#include<bits/stdc++.h>
#include
#include
using namespace std;
int comp(int a,int b)
{
string ac = to_string(a);
//cout<<ac;
string bc = to_string(b);
//cout<<bc;
int i =0,digit1,digit2;
while(ac[i]!=NULL || bc[i]!=NULL)
{
digit1 = ac[i] - ‘0’;
digit2 = bc[i] - ‘0’;
if(digit1 == digit2)
i++;
else
break;
}
if(digit1>digit2)
return 1;
else
return 0;
}
void sort_arr(vector arr,int s)
{
int t;
for(int i=0;i<s;i++)
{
for(int j = i+1;j<s;j++)
{
if(!comp(arr[i],arr[j]))
{
t = arr[i];
arr[i]=arr[j];
arr[j] = t;
}
}
}
for(int i=0;i<s;i++)
{
cout<<arr[i];
}
}
int main() {
int m,temp;
cin>>m;
while(m)
{
int s,t;
cin>>s;
vector arr;
for(int i=0;i<s;i++)
{
cin>>t;
arr.push_back(t);
}
sort_arr(arr,s);
cout<<endl;
arr.clear();
m–;
}
return 0;
}