速贴墙纸

来源:互联网 发布:python3 调用js 编辑:程序博客网 时间:2024/04/20 02:05

描述:

约翰想用墙纸装饰他的房间,但他不确定需要买几卷,已知约翰的房间长“l”米,宽“w”米,高“h”米。墙纸长“10”米,宽“52”厘米。为了以防万一,他想买比他所需要的墙纸长度多百分之十五,你能帮帮他吗?

例如:

wallpaper(4, 3.5, 3) 应该返回 “ten”

CodeWar:

using System;using System.Collections.Generic;public class Wallpaper{    public static string WallPaper(double l, double w, double h)    {        var numberName = new Dictionary<int, string>()        {            { 1, "one" },            { 2, "two" },            { 3, "three" },            { 4, "four" },            { 5, "five" },            { 6, "six" },            { 7, "seven" },            { 8, "eight" },            { 9, "nine" },            { 10, "ten" },            { 11, "eleven" },            { 12, "twelve" },            { 13, "thirteen" },            { 14, "fourteen" },            { 15, "fifteen" },            { 16, "sixteen" },            { 17, "seventeen" },            { 18, "eighteen" },            { 19, "nineteen" },            { 20, "twenty" }        };        return l > 0 && w > 0 && h > 0 ? numberName[(int)Math.Ceiling(2 * h * (l + w) / 5.2 * 1.15)] : "zero";    }}
0 0