# Sorry again
# My personal decision for 'doesn't', 'anybody'd', 'close-up' etc:
# treat 'oesn', 'anyb', 'lose' as valid strings
# but not 'sn't', 'dy'd', 'se-u' (or 'esnt', 'odyd', 'seup')
# 
# Here it is (seemingly different from other solutions posted to date)

use strict;
use warnings;
my %strings;
while (<>) {
    chomp;
    next if length $_ < 4;
    for my $i (0..length($_) - 4) {
        my $substring = lc substr($_, $i, 4);
        $strings{$substring}++;
        $strings{$substring} .= ":$_";
    }
}
open Q_OUT, ">questions" or die "Cannot open questions: $!";
open A_OUT, ">answers" or die "Cannot open answers: $!";
for (sort keys %strings) {
    my ($count, $word) = split /:/, $strings{$_};
    next if $count > 1 or /[^a-zA-Z]/;
    print Q_OUT "$_\n";
    print A_OUT "$word\n";
}
close Q_OUT;
close A_OUT;

