Hi, how am i supposed to solve this question without using vectors since we have not studied it yet?
How to solve it
@Parikalp10 hey you can use array, you can always use array in place of vector.
Use an array and custom comparator to solve this question.
If this resolves your doubt mark it as resolved.
Is there any way to convert them into a string and use the compare function or do i have to use the append method in arrays?
@Parikalp10
Hey you were passing string by value which causes extra overhead , always pass parameters in comp as const and by reference unless you specifically want to make changes.
Also you were not using the compare function in write way.
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool comp(const string & a,const string& b){
string X=a+b;
string Y=b+a;
return X>Y;
}
int main() {
int t,n,i,j;
string a[100000];
cin>>t;
for(i=0;i<t;i++){
cin>>n;
for(j=0;j<n;j++){
cin>>a[j];
}
sort(a,a+n,comp);
for(j=0;j<n;j++){
cout<<a[j];
}
cout<<endl;
}
return 0;
}
If this resolves your doubt mark it as resolved.
Thank you for this but I dont know about const? Any help on that
@Parikalp10 writing const before the parameter makes it constant in the function, you would not be able to modify it.
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.