fork download
  1. interface M{static void main(String[]P){String S="swallowed",T="There was an old lady who "+S+" a |.",e="I don't know why she "+S+" that fly,\n",a[]={"fly","spider","bird","cat","dog","horse"},q[]={"","That wriggled and iggled and jiggled inside her.","How absurd |","Imagine that |","What a hog |",null};for(int i=0,j;i<6;){p(T.replace("|",a[i]));if(q[i]==null){p("She died of course.");break;}if(!q[j=i++].isEmpty())for(p((q[j].replace("|","to swallow a "+a[j])).trim());j>0;)p("She swallowed the "+a[j]+" to catch the "+a[--j]+",");p(e+"Perhaps she'll die.\n");}}static<T>void p(T v){System.out.println(v);}}
Success #stdin #stdout 0.19s 55128KB
stdin
Standard input is empty
stdout
There was an old lady who swallowed a fly.
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a spider.
That wriggled and iggled and jiggled inside her.
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a bird.
How absurd to swallow a bird
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a cat.
Imagine that to swallow a cat
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a dog.
What a hog to swallow a dog
She swallowed the dog to catch the cat,
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a horse.
She died of course.