脚本比赛 (Event 8,猜随机数)
时间:2008-03-12 来源:starB6
#!/usr/bin/perl -w
use strict; my $data=int(rand(50));
my $time=0;
my $biggertime=0;
my $smallertime=0;
print "please input the data:\n";
my $input=<STDIN>;
chomp($input); #AARONVOX: #while (1)
#{
# do something
# my $xxx = <>;
# goto AARONVOX if $xxx =~ /Hello/;
#} AARONVOX:
while ($input gt $data )
{
$biggertime+=1;
print " the input is too LARGE ! please input again;\n";
$input=<STDIN>;
chomp($input);
goto AARONVOX if $input gt $data;
goto BARONVOX if $input lt $data;
}
BARONVOX:
while ($input lt $data )
{
$smallertime+=1;
print " the input is too small ! please input again;\n";
$input=<STDIN>;
chomp($input);
goto AARONVOX if $input gt $data;
goto BARONVOX if $input lt $data;
}
$time=$smallertime+$biggertime+1;
print " the input it : $input,this rand is : $data ,\n";
print "your input times is $time:\n";
print " Your input is bigger has times : $biggertime\n ";
print "your input is smaller has times :$smallertime\n";
use strict; my $data=int(rand(50));
my $time=0;
my $biggertime=0;
my $smallertime=0;
print "please input the data:\n";
my $input=<STDIN>;
chomp($input); #AARONVOX: #while (1)
#{
# do something
# my $xxx = <>;
# goto AARONVOX if $xxx =~ /Hello/;
#} AARONVOX:
while ($input gt $data )
{
$biggertime+=1;
print " the input is too LARGE ! please input again;\n";
$input=<STDIN>;
chomp($input);
goto AARONVOX if $input gt $data;
goto BARONVOX if $input lt $data;
}
BARONVOX:
while ($input lt $data )
{
$smallertime+=1;
print " the input is too small ! please input again;\n";
$input=<STDIN>;
chomp($input);
goto AARONVOX if $input gt $data;
goto BARONVOX if $input lt $data;
}
$time=$smallertime+$biggertime+1;
print " the input it : $input,this rand is : $data ,\n";
print "your input times is $time:\n";
print " Your input is bigger has times : $biggertime\n ";
print "your input is smaller has times :$smallertime\n";
相关阅读 更多 +
排行榜 更多 +