ZOJ( 1001 | 1048 | 1109 | 1151 | 1240 | 1241 | 1608 | 1808 ) Perl版本

來源:互聯網
上載者:User

 

######################### 1001 ##############################

 

use 5.010;while(<>){ my @num = split; say $num[0] + $num[1];}

######################### 1048 ##############################

my $n = 12;my $sum = 0;while ( $n -- ){ chomp(my $num = <STDIN>) ; $sum += $num;}printf "/$%.2f/n", $sum / 12 ;
######################### 1109 ##############################

use 5.010;my %hash;while(<STDIN>){ last if $_ eq "/n" ; my($value, $key) = split; $hash{$key} = $value;}while(<STDIN>){ chomp; exists $hash{$_} ? say "$hash{$_}" : say "eh";}
######################### 1151 ##############################

my $case = <STDIN>;for (1..$case){ chomp(my $n = <STDIN>); redo if $n eq ''; print "/n" if $_ != 1 ; for (1..$n){ chomp($_ = <STDIN>); my @arr = split; while(@arr){ print reverse split '', shift @arr; print " " if @arr ; #最後一行不加空格 } print "/n"; }}

######################### 1240 ############################

 

 

 

chomp(my $num = <STDIN>);my $nums = 1;while($num --){ chomp(my $str = <STDIN>); printf "String #%d/n",$nums++; my @arr = split("",$str); $str = shift @arr; while($str){ $str eq "Z" ? print "A" : print chr(ord($str)+1); $str = shift @arr; } print "/n/n";}

######################### 1241 ##############################

my $n = 1;while(<STDIN>){ my ($a,$b,$c) = split; last if $a + $b + $c == 0 ; printf "Triangle #%d/n",$n++; printf "c = %.3f",sqrt ($a**2 + $b**2 ) if $c == -1; $c > $a ? printf "b = %.3f",sqrt ($c**2 - $a**2 ):print "Impossible." if $b == -1; $c > $b ? printf "a = %.3f",sqrt ($c**2 - $b**2 ):print "Impossible." if $a == -1; print "/n/n";}

######################### 1608 ##############################

use 5.010;while(<>){ my($a, $b, $r1, $r2) = split; my $total_r= $r1 + $r2 ; (say "No") && next if $total_r > $a || $total_r >$b; sqrt(($a-$total_r)**2 + ($b-$total_r)**2) < $total_r ? say "No" : say "Yes";}

######################### 1808 ##############################

my $flag = 0;my $count = 1;my @arr;while (<STDIN>){ chomp; if ($_ == 9){ printf "Set %d is immediately decodable/n",$count++ if $flag != 1; $#arr = -1; $flag = 0; next; } next if $flag == 1; push @arr, $_; for(my $i =0; $i <= $#arr-1 && $flag != 1; $i++ ){ (printf "Set %d is not immediately decodable/n",$count++) && ($flag = 1) if /^$arr[$i]/ ; }}

-------------------------------------- Separate Line -----------------------------------------

說明幾點:1、題目和代碼都很簡單,所以代碼就沒有加註釋。2、如果代碼有錯誤或者可以改進的希望能告訴我一下,互相提高!3、共用是種美德 !

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.