Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
26
Task/ABC-Problem/Perl/abc-problem-1.pl
Normal file
26
Task/ABC-Problem/Perl/abc-problem-1.pl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
|
||||
sub can_make_word {
|
||||
my ($word, @blocks) = @_;
|
||||
$_ = uc join q(), sort split // for @blocks;
|
||||
my %blocks;
|
||||
$blocks{$_}++ for @blocks;
|
||||
return _can_make_word(uc $word, %blocks)
|
||||
}
|
||||
|
||||
|
||||
sub _can_make_word {
|
||||
my ($word, %blocks) = @_;
|
||||
my $char = substr $word, 0, 1, q();
|
||||
|
||||
my @candidates = grep 0 <= index($_, $char), keys %blocks;
|
||||
for my $candidate (@candidates) {
|
||||
next if $blocks{$candidate} <= 0;
|
||||
local $blocks{$candidate} = $blocks{$candidate} - 1;
|
||||
return 1 if q() eq $word or _can_make_word($word, %blocks);
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue