#include
#include
#include
using namespace std;
int main() {
string s[100];
int n=0,t;
cin>>t;
while(t>0)
{
cin>>n;
for(int i=0 ; i<n ; i++)
{
getline(cin,s[i]);
}
sort(s,s+n);
for(int i=0 ; i<n ; i++)
cout<<s[i];
}
return 0;
}
#include
#include
#include
using namespace std;
int main() {
string s[100];
int n=0,t;
cin>>t;
while(t>0)
{
cin>>n;
for(int i=0 ; i<n ; i++)
{
getline(cin,s[i]);
}
sort(s,s+n);
for(int i=0 ; i<n ; i++)
cout<<s[i];
}
return 0;
}
hello @amangupta
getline will read the complete line and store it in s[0] but what we want is to read each string of the line and store at s[i].
so dont use getline.
cin>>s[i]; will work fine.
also there is logic error in ur code.
for input 2 21 ur code will order them as 212 but correct order is 221 to correct it define ur own comparator for sorting.
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.