Giter Club home page Giter Club logo

length's Introduction

#length

##题目介绍 您要做的是一个长度单位转化和计算工具,能够把不同的长度单位转换为标准长度(米),并且可以在不同单位之间进行加减运算。

输入文件

输入文件input.txt的内容可分为两部分:

  1. 不同单位和标准长度米的转换规则, 比如

1 mile = 1609.344 meters, 代表1英里等于1609.344米;

  1. 转换前或者计算前的单位,比如 1.2 miles // 一个长度 1.2 miles + 1 fath - 0.2 meters // 单位可能不同的长度之间的加减运算

您要做的

我们期望您编写一个应用程序,可以读取输入文件,了解不同单位与米之间的转换规则后,把以不同单位表示的长度都转换为标准单位米;同时计算不同单位长度的加减表达式,得到以米为单位的结果。

做题要求:

  • 请一定Fork本仓库再做题目

  • 使用的编程语言不限

  • 输出结果为文件"output.txt",其格式见下面说明

  • 源代码和结果文件"output.txt"上传到您的GitHub代码库中

  • 结果文件“output.txt”一定要放到代码库的根目录下

输出文件格式

该文件的格式共有12行,并严格遵守以下规则:

  • 第1行是您在渣打编程马拉松官网上报名时的注册邮箱,比如[email protected]

  • 第2行是空行

  • 第3行至第12行,每行显示1个计算结果,比如1931.21 m

  • 计算结果要求精确到小数点后两位

  • 计算结果均以字母m结尾,请注意数字和字母m之间有一个空格。

length's People

Contributors

aqingsao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

length's Issues

单位转换有错误

1 inch = 0.00254 m
1 foot = 0.03048 m
should be
1 inch = 0.0254 m
1 foot = 0.3048 m

My perl code

!/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;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.