String sort- how do i sort bat and batman

code:
include bits/stdc++.h
using namespace std;
int main() {
int n;
cin>>n;
string ch[n];
for(int i=0;i<n;i++)
cin>>ch[i];

sort(ch,ch+n);
for(int i=0;i<n;i++)
cout<<ch[i]<<endl;
return 0;

}

@vashishthkuntal.gajjar2019, C++ stl allows you to customize your sort function by passing a third argument, which is a function, often called as comparator, This comparator function returns a value; convertible to bool, which basically tells us whether the passed “first” argument should be placed before the passed “second” argument or not.

if you are not aware of this concept then i will suggest to learn about it.

refer this code for better understanding :-

In case of any doubt feel free to ask :slight_smile:
Mark your doubt as RESOLVED if you got the answer

Maybe it could be done using maps

you very well can try using maps but it might become complex.