Question

Suppose, we have input strings in a form I have/had alot/none/zero money.

I would like to have a set of output strings as follows (example 1):

I have alot money

I have none money

I have zero money

I had alot money

I had none money

I had zero money

But then, real task here, is to be able to choose one or more, or none input substrings to ignore. So, the output strings would look like this:

I money

or

first example

or

I alot money

I none money

I zero money

or

I

or

money

I hope you got the point. How can i do this in the way, friendliest to cpu cycles ?

Ok, to break the ice, this is what im Not willing to do, but considering until brighter ideas:

  1. generate all the output strings (mentioned, example 1).
  2. iterating through strings, i filter out ones that meet my criteria, replace unwanted substrings with "".
  3. put the resulting string into final output array only if it is not already there.

Also, the answer to why do i care for cpu cycles, is simple : the longer this task takes, the longer it will block worker thread.

No correct solution

OTHER TIPS

This simplest way is to find all the spaces and / character and put individual word into a two-level list, you then get a structure like this:

  • I
  • have, had
  • a lot, none, zero
  • money
  • .

Now you just loop thru the tree and generate a result string.

To push it to an overkill, you may also write a token parser instead of doing strchr.

How can i do this in the way, friendliest to cpu cycles ?

Why do you care?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top