Strings and indexes in C++ -



Strings and indexes in C++ -

i learning c++ , doing online challenges. however, seems of "normal" challenges stuck. i'm not sure if i'm lacking of knowledge, or overthinking it. anyway, appreciate if help me.

i trying challenge: input number "n" example, , have input "n" strings afterwards.

then have find smallest amount of prefixes each string typen , create sure not repeating.

for example, string "stackoverflow" has many prefixes: s,st,sta,stac,stack,stacko,stackov,stackove,stackover,stackoverf,stackoverfl,stackoverflo,stackoverflow.

all these prefixes of stackoverflow. so, if have string "standup", have type stackoverflow - stac because there sta in standup already, stan standup.

thanks in advance.

simplest version can think of;

sort list of words in alphabetical order. append re-create of sec lastly word list.

for each word in list, unique prefix number of letters makes unique compared next word in list.

an example, stackoverflow, standup, seer.

the list becomes;

seer stackoverflow standup stackoverflow seer requires `se` unique compared `stackoverflow`. stackoverflow requires `stac` unique compared `standup`. standup requires `stan` unique compared `stackoverflow`.

done.

c++ string indexing

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -