StringSort.cpp: In function ‘bool mycompare(std::string, std::string)’:
StringSort.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
29 | }
| ^
#include
#include
#include
using namespace std;
bool mycompare(string a,string b)
{
char ch1=a[0];
char ch2=b[0];
if(ch1>ch2)
{
return a<b;
}
else
if(ch1==ch2)
{
int len1=a.length();
int len2=b.length();
if(len1>len2)
{
return a>b;
}
else
{
return b>a;
}
}
}
int main()
{
int n;
cin>>n;
cin.get();
string S[100];
for (int i = 0; i < n; i++)
{
getline(cin,S[i]);
}
sort(S,S+n,mycompare);
for (int i = 0; i < n; i++)
{
cout<<S[i]<<endl;
}
return 0;
}