Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My perl code #7

Open
TaurusYin opened this issue Aug 5, 2013 · 2 comments
Open

My perl code #7

TaurusYin opened this issue Aug 5, 2013 · 2 comments

Comments

@TaurusYin
Copy link

!/usr/bin/perl

open FH,'<.\input.txt';
print "[email protected]"."\n";
print "\n";
my @arr=;
my $row;
my @set;
my @Result;
my @cal;
my @re_cal;
my $max=0;
my $max_item=0;
foreach $row(@arr)
{
if($row=/=/)
{
push @set,$row;next;
}
unless($row=
/^\s*$/) #space match
{
push @Result,$row;
}

}
foreach my$item (@set)
{
#@cal = split " ",$item;
#push @re_cal,@cal;
if($item =~ /1 (\S+) = (\S+) m/)
{
@cal = ($1,$2);
push @re_cal, @cal;
}
}
my @calu;
my $cal=0;
my $yu;
foreach my$item (@Result)#对行遍历
{
@calu = split " ",$item;
for(my $y=1;$y<=$#calu;$y+=3) #对等式进行遍历
{
$max = 0;
$max_item = 0;
$yu = $calu[$y-1];
$cal = $calu[$y];

        for(my$i=0;$i<$#re_cal;$i+=2)#选取相似匹配的单词 单数单词 与复数单词 匹配 通过比较每个单词选出匹配度最高的单词
        {
           #if($2 eq $re_cal[$i])
                ($re_cal[$i]->[0])=0;
                my @er1 = split "",$cal;
                my @er2 = split "",$re_cal[$i];
                for(my$j=0;$j<$#er1;$j++)
                {
                    if($er1[$j] eq $er2[$j])
                    {
                        ($re_cal[$i]->[0])++;
                    }
                }
                if($max < $re_cal[$i]->[0])
                {
                    $max = $re_cal[$i]->[0];
                    $max_item = $i;

                }



        }
                if($calu[$y-2] eq '+')            
                {
                     $final_result += $re_cal[$max_item+1]*$yu;next;
                }
                if($calu[$y-2] eq '-')
                {
                     $final_result -= $re_cal[$max_item+1]*$yu;next;
                }
                if($calu[$y-2] eq '*')            
                {
                     $final_result *= $re_cal[$max_item+1]*$yu;next;
                }
                if($calu[$y-2] eq '\')
                {
                     $final_result \= $re_cal[$max_item+1]*$yu;next;
                }
                else
                {
                     $final_result = $re_cal[$max_item+1]*$yu;
                }                        
    }
    printf "%.2f",$final_result;
    print " "."m";
    print "\n";
    $max=0;
    $max_item=0;
}
@crazyboysk
Copy link

我了解了,程序要求最好是能读取任意单词表示的单位进行计算,就是要比对最合适的词确定单位的单复数来计算,这个我一开始没那么想,可以改一下实现这个功能,我现在是将一些单位及其复数形式在程序预定,然后根据读入的数据换算关系进行下边的等式计算,请问我需要修改程序文件再发回去么?谢谢

At 2013-08-05 11:18:37,ensalty [email protected] wrote:

#!/usr/bin/perl
open FH,'<.\input.txt';
print "[email protected]"."\n";
print "\n";
my @arr=;
my $row;
my @set;
my @Result;
my @cal;
my @re_cal;
my $max=0;
my $max_item=0;
foreach $row(@arr)
{
if($row=/=/)
{
push @set,$row;next;
}
unless($row=
/^\s*$/) #space match
{
push @Result,$row;
}

}
foreach my$item (@set)
{
#@cal = split " ",$item;

#push @re_cal,@cal;
if($item =~ /1 (\S+) = (\S+) m/)
{

    @cal = ($1,$2);
    push @re_cal, @cal;

print $1." ".$2."\n";
}
}
my @calu;
my $cal=0;
my $yu;
foreach my$item (@Result)#对行遍历
{
@calu = split " ",$item;
for(my $y=1;$y<=$#calu;$y+=3) #对等式进行遍历
{
$max = 0;
$max_item = 0;
$yu = $calu[$y-1];
$cal = $calu[$y];

    for(my$i=0;$i<$#re_cal;$i+=2)#选取相似匹配的单词 单数单词 与复数单词 匹配 通过比较每个单词选出匹配度最高的单词
    {
       #if($2 eq $re_cal[$i])
            ($re_cal[$i]->[0])=0;
            my @er1 = split "",$cal;
            my @er2 = split "",$re_cal[$i];
            for(my$j=0;$j<$#er1;$j++)
            {
                if($er1[$j] eq $er2[$j])
                {
                    ($re_cal[$i]->[0])++;
                }
            }
            if($max < $re_cal[$i]->[0])
            {
                $max = $re_cal[$i]->[0];
                $max_item = $i;

            }



    }
            if($calu[$y-2] eq '+')            
            {
                 $final_result += $re_cal[$max_item+1]*$yu;next;
            }
            if($calu[$y-2] eq '-')
            {
                 $final_result -= $re_cal[$max_item+1]*$yu;next;
            }
            if($calu[$y-2] eq '*')            
            {
                 $final_result *= $re_cal[$max_item+1]*$yu;next;
            }
            if($calu[$y-2] eq '\')
            {
                 $final_result \= $re_cal[$max_item+1]*$yu;next;
            }
            else
            {
                 $final_result = $re_cal[$max_item+1]*$yu;
            }                        
}
printf "%.2f",$final_result;
print " "."m";
print "\n";
$max=0;
$max_item=0;

}


Reply to this email directly or view it on GitHub.

@aqingsao
Copy link
Owner

aqingsao commented Aug 5, 2013

Hi, crazyboysk
您最好Fork指定的代码库(aqingsao/length),这样您就有了自己的代码库(yourname/length),把代码提交到您的代码库上即可。记得把代码和output.txt都要提交到您的代码库上,具体请参考README。
如果您不熟悉github怎么用,也可以把代码和output.txt发送到官方邮箱。

regards
Xiaoqing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants