One of the testcases is showing runtime error in this code

#include
#include
#include
using namespace std;
bool compare( string x, string y){
if( x[0] == y[0]){
return x.length() > y.length();
}
else{
return x < y;
}
}
int main() {
int n;
cin >>n;
string s[100];

cin.ignore();
for( int i = 0; i <=n; i++){
	getline( cin, s[i]);
}
sort( s , s + n, compare);
for( int i = 0; i < n; i++){
	cout << s[i] << endl;
}
return 0;

}

hi @akki56756_bab14f919dbad123
Refer this -->

#include <iostream>
#include <algorithm>
using namespace std;


int compareTo(string s1, string s2) {

       int i = 0;      

       while (i < s1.length() && i < s2.length()) {

           if (s1[i] > s2[i]) {

               return 1;
           } else if (s1[i] < s2[i]) {
               return -1;
           }
           i++;

       }

       if (s1.length() > s2.length()) {
           return -1;
       } else {
           return 1;
       }

   }
void sortfunc(string arr[], int n) {

       for (int i = 0; i < n; i++) {

           for (int j = 0; j < n - i - 1; j++) {

               if (compareTo(arr[j], arr[j + 1]) > 0) {

                   string temp = arr[j];
                   arr[j] = arr[j + 1];
                   arr[j + 1] = temp;
               }

           }
       }

   }

int main() 
{

   int n;
   cin>>n;
   string* str = new string[n];
   cin.ignore();
   for(int i=0;i<n;i++)
   {   
       cin>>str[i];
   }
   sortfunc(str, n);
   for(int i=0;i<n;i++)
   {
       cout<<str[i]<<endl;
   }
}

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.