Back
Close

Bulk Email Generator

Statement

 Goal

You're coding on CG, minding your own business, when a notification pops out of nowhere. Some level 6 PHP coder is following you! It's all fine and dandy. You click on the dismiss button and move on.

Except it doesn't work. The dreaded red popup appears: “Error 492, please send us an email at coders@codingame.com”. Being the disciplined coder you are, you comply.

But the notification is still there. So you click it again. And read the popup again. And email coders again. But the notification is still there… You can't really send them the same email all the time, that would be boring!

It's time for some automation!

You are given a bulk email template. You are to expand it to an actual email by selecting a clause randomly when given a choice.

Choices are indicated by (parenthesized text), with clauses separated by pipe symbols |.

Random is defined as using the JBM level-0 twister: “for the ith choice, pick the ith clause (modulo the number of clauses)”.
Input
Line 1: the number N of lines of text to follow
Next N lines: the email template

Important: the email template is the N lines as a whole. This is *not* a line-based problem!
Output
The expanded email.
Constraints
N < 10000
Total template size is less than 10000 characters as well.
Choices don't nest.
Example
Input
3
This is the (first|second|third) choice.
This is the (first|second|third) choice.
This is the (first|second|third) choice.
Output
This is the first choice.
This is the second choice.
This is the third choice.

Tags
String manipulation

Difficulty
Easy

Test cases
Example Test
Input
3 This is the (first|second|third) choice. This is the (first|second|third) choice. This is the (first|second|third) choice.
Output
This is the first choice. This is the second choice. This is the third choice.

Counterexample Validator
Input
3 This is the (third|second|first) choice. This is the (third|second|first) choice. This is the (third|second|first) choice.
Output
This is the third choice. This is the second choice. This is the first choice.

CG Email Test
Input
7 (Hello|Hi|Bonjour|Salut|Hey) (les amis|coders|bande de @$%*), I keep getting an error( 492|) in the notification area. Are you aware of that? (Bye|Ciao|Fsck off|Best regards), Your Name Here
Output
Hello coders, I keep getting an error 492 in the notification area. Are you aware of that? Best regards, Your Name Here

JBM Email Validator
Input
13 Dear (JBM|Brian|Charlie|Waldo), I (wish|would like) to (express|say|utter) that I am sorry for my (surprise|unexpected and) (crappy|unethical|stupid) (inappropriate|rude) behavior towards you. I (wanna|would like to) apologize for such behavior. I (regret|am sorry for) what happened (last time|yesterday). I was bogged down with (personal issues|work pressure) that I did not realize that you were trying to (be a prick|help me). I have realized that it was insulting for you as the whole (office|world|crowd) was watching. I promise you that this act of mine won't be repeated again. -With (regards|pride|hate), Anna Nonymous.
Output
Dear JBM, I would like to utter that I am sorry for my unexpected and unethical rude behavior towards you. I wanna apologize for such behavior. I am sorry for what happened last time. I was bogged down with work pressure that I did not realize that you were trying to be a prick. I have realized that it was insulting for you as the whole crowd was watching. I promise you that this act of mine won't be repeated again. -With regards, Anna Nonymous.

Edge Cases Test
Input
7 (No choice) (Empty choice|) Lotsa (1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100) choices Does it (wrap|unwrap)? (Multi line|Multi line)
Output
No choice Lotsa 3 choices Does it unwrap? Multi line

Edge Cases Validator
Input
7 (|Empty choice) (No hope) Lotta (1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100) choice Does it (curve|blend)? (Lines by two|Two lines)
Output
No hope Lotta 3 choice Does it blend? Lines by two

Comment Spam Test
Input
1 (You must|You need to|You have to|You should) (take advantage of|make the most of|benefit from|take full advantage of) (all the|all of the|each of the|every one of the) software advancements that (happen to be|are actually|are|are generally) (a successful|an effective|an excellent|a prosperous) (Internet marketer|Online marketer|Internet entrepreneur|Affiliate marketer). (If your|In case your|Should your|When your) work (begins to|starts to|actually starts to) suffer, (the competition|your competition|competition|your competitors) could (leave you|make you|create) (in the|within the|inside the|from the) dust. Show (that you are|that you will be|that you are currently|you are) always (on the|around the|in the|about the) (cutting edge|innovative|leading edge|really advanced), (and they will|and they can) (learn to|learn how to|figure out how to|discover how to) trust (you and your|both you and your|you and the|your) products.
Output
You must make the most of each of the software advancements that are generally a successful Online marketer. Should your work starts to suffer, the competition could leave you inside the dust. Show you are always on the innovative, and they will discover how to trust you and your products.

Comment Spam Validator
Input
1 (Heya) (You must|You need to|You have to|You should) (take advantage of|make the most of|benefit from|take full advantage of) (all the|all of the|each of the|every one of the) software advancements that (happen to be|are actually|are|are generally) (a successful|an effective|an excellent|a prosperous) (Internet marketer|Online marketer|Internet entrepreneur|Affiliate marketer). (If your|In case your|Should your|When your) work (begins to|starts to|actually starts to) suffer, (the competition|your competition|competition|your competitors) could (leave you|make you|create) (in the|within the|inside the|from the) dust. Show (that you are|that you will be|that you are currently|you are) always (on the|around the|in the|about the) (cutting edge|innovative|leading edge|really advanced), (and they will|and they can) (learn to|learn how to|figure out how to|discover how to) trust (you and your|both you and your|you and the|your) products.
Output
Heya You need to benefit from every one of the software advancements that happen to be an effective Internet entrepreneur. When your work actually starts to suffer, your competition could make you from the dust. Show that you are always around the leading edge, and they can learn to trust both you and your products.

More Edge Cases Test
Input
7 (|Empty choice) (No choice) Lotsa (1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100) choices Does it (curve|blend)? (Lines by two|Two lines)
Output
No choice Lotsa 3 choices Does it blend? Lines by two

More Edge Cases Validator
Input
7 (|) (The void) Where am (0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100) I Does it (inspire|transpire)? (Lines by two|Two lines)
Output
The void Where am 2 I Does it transpire? Lines by two

Solution language

Solution

Stub generator input