Round 1B Problem A. File Fix-it
よく考えたらGCJってなんの言語使ってもいいんだよね。
これ、木構造扱わないといけないし、文字列処理が入ってくるので、Perlを使って書いてみた。
#!/usr/bin/perl $T = <>; for $no(1..$T) { $tree = {}; $line = <>; chomp $line; ($N, $M) = split / /, $line; for $i(1..$N) { $dir = <>; chomp $dir; @a = split /\//, $dir; makedir($tree, \@a); } $count = 0; for $i(1..$M) { $dir = <>; chomp $dir; @a = split /\//, $dir; $res = makedir($tree, \@a); #print "\t$res\n"; $count += $res; } print "Case #$no: $count\n"; } sub makedir { my ($tree, $a) = @_; my $count = 0; my $path = join "/", @$a; for $i(1..$#{$a}) { unless($tree->{$a->[$i]}) { $count++; $tree->{$a->[$i]} = {}; } $tree = $tree->{$a->[$i]}; } return $count; }