微软2014编程之美初赛第一场——题目1 : 焦距

【来源】

题目1 : 焦距

【分析】

题目中已经给出公式,直接套用公式即可。若单位不统一,将单位化统一。

【代码】

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int T;
    cin >> T;
    for (int i = 0; i < T; ++i){
        double focal;
        string unitf;
        double ccd;
        string unitc;
        double image;
        string uniti;
        cin >> focal >> unitf >> ccd >> unitc >> image >> uniti;
        if (unitf == "dm"){
            focal /= 10.0;
        }
        else if (unitf == "cm"){
            focal /= 100.0;
        }
        else if (unitf == "mm"){
            focal /= 1000.0;
        }
        else if (unitf == "um"){
            focal /= 1000000.0;
        }
        else if (unitf == "nm"){
            focal /= 1000000000.0;
        }

        if (unitc == "dm"){
            ccd /= 10.0;
        }
        else if (unitc == "cm"){
            ccd /= 100.0;
        }
        else if (unitc == "mm"){
            ccd /= 1000.0;
        }
        else if (unitc == "um"){
            ccd /= 1000000.0;
        }
        else if (unitc == "nm"){
            ccd /= 1000000000.0;
        }

        double result = image * focal / ccd;
        
        cout << "Case " << i + 1 << ": " << (int)((result * 100) + 0.5) / 100.0 << "px" << endl;
    }

    //system("pause");
    return 0;
}
【点评】

本题为简单题。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值