Okay,
So I am having a bit of an issue phrasing this question. Perhaps it's easier to present an example:
Suppose we consider the four seasons: Winter, Spring, Summer and Fall (in that particular order). And suppose now that we have the following text:
I love the Summer.
The Winter is not a good season.
Spring brings more joy.
And Fall is the best.
Now, suppose I have a program that reads the file, and upon encountering the first season (in this case, Summer) replaces all other seasons with the first instance. Then, it prints out the text again, this time with the next season, repeatedly, until all seasons have been covered.
For example, the above text should produce the following output:
//..Replace with 'Summer'
I love the Summer.
The Summer is not a good season.
Summer brings more joy.
And Summer is the best.
//.. Replace with 'Winter'
I love the Winter.
The Winter is not a good season.
Winter brings more joy.
And Winter is the best.
//.. Replace with 'Spring'
I love the Spring.
The Spring is not a good season.
Spring brings more joy.
And Spring is the best.
//.. Replace with 'Fall'
I love the Fall.
The Fall is not a good season.
Fall brings more joy.
And Fall is the best.
Now, however, if the poem had read:
I love the Fall.
The Winter is not a good season.
Spring brings more joy.
And Summer is the best.
The program would start by replacing every instance of a season with "Fall", and then do the same for Winter, Spring and Summer. (Since Winter, Spring, Summer, Fall) is the default order.
In short: the first season encountered is defines the first iteration of he "replace" action. That is, if "Summer" is encountered, the entire text has its seasons replaced with Summer. Then with Winter, Spring and Fall. If "Spring" is encountered first, the text first replaces all the seasons with "Spring", then Winter, Summer, and Fall.
I know one could do this by writing a a series of conditional statements, such as:
if summer
replace summer
replace winter
replace spring
replace fall
else if spring
replace spring
replace winter
replace summer
replace fall
else if winter
replace winter
replace spring
replace summer
replace fall
else if fall
replace fall
replace winter
replace spring
replace summer
However, this hardly seems the best way to do so. I know the text has to be replaced with all seasons at some point. I also know that the order of these seasons. The only thing that matters is the first season instance, which then determines which season is to be taken out from its place, and put in front.
If this question made any sense at all, I would highly appreciate some advice. I'm not particularly looking for code, but rather for tips on how to approach such a question.
Thanks guys.