Sorting of strings according to length & alphabetically

Please help me to find the error in this below code

#include
#include<bits/stdc++.h>
using namespace std;

bool comp (string a, string b)
{
if (a.length()>=b.length() && a.substr(0,b.length())==b)
{
return true;
}
else if (b.length()>a.length() && b.substr(0,a.length())==a)
{
return false;
}
else
{
return a<b;
}
}
int main()
{
vector a;
int n;
cin>>n;
if(n==0)
{
return 0;
}
if(n<0)
n=n*-1;

for (int i=1; i<=n;i++ )
{
	string s;
	cin>>s;
	a.push_back(s);
}

sort(a.begin(), a.end(), comp);

for (int i=0; i<=a.size()-1; i++)
{
	string m = a[i];
	cout<<m<<",";
}
return 0;

}

hi @Hvarshney
I can see that u have successfully submitted the code and gained full points… is there still anything??

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.

just wanted to clarify then get line is necessary for string ?
or can we directly use cin>>s; to input a string

hi @Hvarshney
u can directly take input of string…
string str;
cin>>str;