Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
20
Task/Odd-word-problem/Perl/odd-word-problem-1.pl
Normal file
20
Task/Odd-word-problem/Perl/odd-word-problem-1.pl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
sub r
|
||||
{
|
||||
my ($f, $c) = @_;
|
||||
return sub { print $c; $f->(); };
|
||||
}
|
||||
|
||||
$r = sub {};
|
||||
|
||||
while (read STDIN, $_, 1) {
|
||||
$w = /^[a-zA-Z]$/;
|
||||
$n++ if ($w && !$l);
|
||||
$l = $w;
|
||||
if ($n & 1 || !$w) {
|
||||
$r->(); $r = sub{};
|
||||
print;
|
||||
} else {
|
||||
$r = r($r, $_);
|
||||
}
|
||||
}
|
||||
$r->();
|
||||
26
Task/Odd-word-problem/Perl/odd-word-problem-2.pl
Normal file
26
Task/Odd-word-problem/Perl/odd-word-problem-2.pl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
sub rev
|
||||
{
|
||||
my $c;
|
||||
read STDIN, $c, 1;
|
||||
if ($c =~ /^[a-zA-Z]$/) {
|
||||
my $r = rev();
|
||||
print $c;
|
||||
return $r;
|
||||
} else {
|
||||
return $c;
|
||||
}
|
||||
}
|
||||
|
||||
while (read STDIN, $_, 1) {
|
||||
$w = /^[a-zA-Z]$/;
|
||||
$n++ if ($w && !$l);
|
||||
$l = $w;
|
||||
if ($n & 1) {
|
||||
print;
|
||||
} else {
|
||||
my $r = rev();
|
||||
print $_;
|
||||
print $r;
|
||||
$n = 0; $l = 0;
|
||||
}
|
||||
}
|
||||
24
Task/Odd-word-problem/Perl/odd-word-problem-3.pl
Normal file
24
Task/Odd-word-problem/Perl/odd-word-problem-3.pl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
$|=1;
|
||||
|
||||
while (read STDIN, $_, 1) {
|
||||
$w = /^[a-zA-Z]$/;
|
||||
$n++ if ($w && !$l);
|
||||
$l = $w;
|
||||
if ($n & 1 || !$w) {
|
||||
close W; while(wait()!=-1){}
|
||||
print;
|
||||
} else {
|
||||
open W0, ">&", \*W;
|
||||
close W;
|
||||
pipe R,W;
|
||||
if (!fork()) {
|
||||
close W;
|
||||
<R>;
|
||||
print $_;
|
||||
close W0;
|
||||
exit;
|
||||
}
|
||||
close W0;
|
||||
close R;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue