-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07.pl
68 lines (61 loc) · 957 Bytes
/
07.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl -w
use strict;
no warnings 'portable';
use Data::Dumper;
use feature 'say';
use Clipboard;
sub out {
my $out = shift;
if (ref($out)) {
print Dumper($out);
} else {
Clipboard->copy_to_all_selections($out);
print "$out\n";
}
}
my $A;
my @S;
my $size=0;
my @O;
my $sum;
while (<>) {
chomp;
NEXT:
last unless $_;
my @p = split(' ');
my ($a,$b,$c) = @p;
if ($b eq 'cd') {
if ($c eq '..') {
$A--;
push @O, $size;
$sum += $size if ($size < 100000);
$size += pop(@S);
} else {
$A++;
push @S, $size;
$size = 0;
}
next;
}
# ls
while (<>) {
chomp;
if (/^(\d+)/) {
$size+=$1;
} elsif (/^\$/) {
goto NEXT;
}
}
goto NEXT;
}
while ($A--) {
push @O, $size;
$sum += $size if ($size < 100000);
$size += pop(@S);
}
out($sum);
my $T = $size-40000000;
for my $c (sort {$b <=> $a} @O) {
$sum = $c if $c > $T;
}
out($sum);