This isn't rocket science. LoL
Write a program or function that takes in a single-line string. You can assume it only contains printable ASCII. Print or return a string of an ASCII art rocket such as
|
/_\
|I|
|N|
|D|
|I|
|A|
|_|
/___\
VvV
with the input string written from top to bottom on the fuselage. In this case the input was Earth. The height of the rocket (including flames) is always the length of the string plus five.
More Examples:
[empty string]
|
/_\
|_|
/___\
VvV
a
|
/_\
|a|
|_|
/___\
VvV
SPACE
|
/_\
|S|
|P|
|A|
|C|
|E|
|_|
/___\
VvV
Solutions
Jump to C, JavaScript, PHP, C# Solution.
You can submit your own solution in comment section in same/different programming language. If your solution is better or in different language we'll add here.
C
#include <stdio.h>
int main() {
char *str="Developer Insider";
for(puts(" |\n /_\\");*str;printf(" |%c|\n",*str++));
puts(" |_|\n/___\\\n VvV");
return 0;
}
JavaScript
<html>
<body>
<input id=I value='Developer Insider' oninput='update()'><pre id=O></pre>
<script>
f=x=>` |
/_\\
|${[...x+'_'].join`|
|`}|
/___\\
VvV`
function update() {
O.textContent=f(I.value)
}
update()
</script>
</body>
</html>
PHP
<?=' |
/_\
|'.join("|\n |",str_split('Developer Insider')).'|
/___\
VvV';
CSharp
Submited by David C. Untalan Jr.
using System;
namespace testcs
{
class Program
{
static void Main(string[] args)
{
rocket("I ♥ C#");
Console.Read();
}
private static void rocket(string p)
{
int i = 0;
Console.Write(" |\n /_\\\n");
while (i < p.Length)
Console.Write(" |{0}|\n", p[i++]);
Console.Write(" |_|\n/___\\\n VvV");
}
}
}