How to store substring in map in defined order

given a string let s =“ABAC”
Now i want to store all the substring in map
so substrings will be
A
AB
ABA
ABAC
B
BA
BAC
A
AC
C

But when i print my map then it will print in lexographical order ie.,
A
AB
ABA
ABAC
AC
B
BA
BAC
C

I need all the substring print exactly in contiguous manner , this approach is used in some other problem so i want to do this , can anyone help me @anon55659401

@samarthtandon help me bro for the above problem.

don’t put in Map as it was always sorted try to put in vector

No but when i use vector it pushes copy also
means
suppose there are two substring is same
“aba” : 1 from index 2 to 5
again “aba” : 1 from index 7 to 9
but map have only one copy while vector has 2.

use set and vector

before pushing the string in vector just check if it is present in set or not
if(set.find(string) == set.end())
then vector.push_back(string);
else
continue;

1 Like

Ok I will try this…