zoukankan      html  css  js  c++  java
  • Perl 笔试题1

    Nvidia 2019 笔试题

    ## 源代码 ```perl #!/usr/bin/perl

    open(IN,"<nv_data1.txt") or die "File does not exist!";
    while (){
    chomp; #删除
    print("(_ "); if()i==0){next}; #跳过第一行
    ((power,)area) = calc($_);#统计当前行单元的面积和功耗

    $total_power += $power;   #统计总面积和功耗
    $total_area += $area;
    if(/^ALU/i){
    $alu_power +=  $power;
    } 
    elsif(/^RAM/i){
        $ram_area +=  $area;	    
    }
    

    }continue{
    $i++;
    }

    功耗和面积计算函数

    sub calc{
    my (string = scalar()_);
    @tmp = split(/s+/,$string); #根据空格划分单元格内容

    return ($tmp[1]*$tmp[3], $tmp[1]*$tmp[2]);
    

    }
    close IN;

    输出

    print("Total area is $total_area ");
    print("Total power is $total_power ");
    print("RAM area is $ram_area ");
    print("ALU power is $alu_power ");

    $RAM_area_percentage = (ram_area/)total_area100;
    $ALU_power_percentage = (alu_power/)total_power
    100;
    print("The percentage of RAM area is $RAM_area_percentage % ");
    print("The percentage of ALU power is $ALU_power_percentage % ");

    ## 程序输出结果
    

    Name: Instance_number Area-per-instance Power-per-instance
    ALU-Adder: 32 945 0.0333
    ALU-Multiplier 16 6347 0.2235
    RAM-Small 8 2239 0.0542
    RAM-Large 2 10943 1.9312
    Control 1 8345 0.2344
    Data-pipe 1 10123 1.3423
    Processor 1 24231 1.0212
    Total area is 214289
    Total power is 11.5355
    RAM area is 39798
    ALU power is 4.6416
    The percentage of RAM area is 18.5721152275665 %
    The percentage of ALU power is 40.2375276320922 %

  • 相关阅读:
    学习笔记之Linux开发(C语言)
    Shell脚本文件操作
    学习笔记之Shell脚本的输出重定向
    学习笔记之正则表达式 (Regular Expressions)
    学习笔记之#pragma
    eclipse启动不了报错java was started but returned exit code=13
    学习笔记之APACHE ANT
    学习笔记之Linux / Shell
    学习笔记之DB2 9 Fundamentals 730
    windows远程关机重启
  • 原文地址:https://www.cnblogs.com/lyc-seu/p/12374066.html
Copyright © 2011-2022 走看看