折叠用自己的方式去月球【难度:1级】:

答案1:

using System;
using System.Collections.Generic;public class Kata
{public static int? FoldTo(double distance){double thickness = 0.0001;if (distance < 0 )return null;if (distance >= 0 &amp;&amp; distance <= thickness)return 0;return (int)Math.Ceiling(Math.Log((distance / thickness), 2));}
}​

答案2:

public class Kata
{public static int? FoldTo(double distance){if (distance < 0)return null;var foldthickness = 0.0001;var amountOfFolds = 0;while (foldthickness < distance){foldthickness *= 2;amountOfFolds++;}return amountOfFolds;}
}​

答案3:

public class Kata
{public static int? FoldTo(double d){if (d < 0) return null;int r = 0;for (double a=0.0001;a<d;a*=2,r++);return r;}
}​

答案4:

public class Kata
{public static int? FoldTo(double distance){if (distance < 0)return null; double cur = 0.0001;var i = 0;while (cur < distance){cur *= 2;i++;}return i;}
}​

答案5:

public class Kata
{public static int? FoldTo(double distance){int count=0;double i=0.0001;while (i<distance){i=i*2;count+=1;}if (distance<0){return null;}return count;}
}​

答案6:

using System;
public class Kata
{public static int? FoldTo(double distance){if (distance < 0)return null;int folds = 0;while (distance > 0.0001){distance /= 2;folds++;}return folds;}
}​

答案7:

public class Kata
{public static int? FoldTo(double distance){double result = 0.0001;int? n = 0;if (distance >= 0){while(result<=distance){n++;result*=2 ;  }}else{n = null;}return n;}
}​

答案8:

public class Kata
{public static int? FoldTo(double distance){int? count;double t;if (distance < 0)return (null);t = 0.0001;for (count = 0; t < distance; count++)t *= 2;return (count);}
}​

答案9:

public class Kata
{public static int? FoldTo(double distance){if (distance < 0){return null;};int result = 0;double thickness = 0.0001;while (thickness < distance){thickness *= 2;result++;};return result;}
}​

答案10:

using System;
public class Kata
{public static int? FoldTo(double distance){if (distance<0) return null;int k = 0;while (distance>0.00001){if (distance <= 0.0001)return k;distance = distance / 2;k++;}           return k;}
}​

C#练习题答案: 折叠用自己的方式去月球【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战相关推荐

  1. C#练习题答案: 字母战争 - 核打击【难度:3级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    字母战争 - 核打击[难度:3级]: 答案1: using System; using System.Text.RegularExpressions; using System.Linq; publi ...

  2. C#练习题答案: 寻找恩人【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    寻找恩人[难度:1级]: 答案1: using System; using System.Linq;public class NewAverage {public static long NewAvg ...

  3. C#练习题答案: 反恐精英系列【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    反恐精英系列[难度:1级]: 答案1: namespace CS {using System;using System.Collections.Generic;public class Kata{pr ...

  4. C#练习题答案: 图片#1 - 重建巴别塔【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    图片#1 - 重建巴别塔[难度:1级]: 答案1: using System.Linq;public static class Kata {public static string Babel(int ...

  5. C#练习题答案: TO DE-RY-PO-陆琪暗号【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    TO DE-RY-PO-陆琪暗号[难度:1级]: 答案1: using System.Linq;public class Kata{public static string Encode(string ...

  6. C#练习题答案: 英雄的根【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    英雄的根[难度:1级]: 答案1: using System;public class IntSqRoot {const int error = 1;public static long IntRac ...

  7. C#练习题答案: scytale的编码器/解码器(古斯巴达密码)【难度:3级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    scytale的编码器/解码器(古斯巴达密码)[难度:3级]: 答案1: using System; using System.Linq; using System.Text.RegularExpre ...

  8. C#练习题答案: 产品和LCMS之间的差异总和【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    产品和LCMS之间的差异总和[难度:1级]: 答案1: using System.Linq;public class Kata {static int gcd(int a, int b) {if(a ...

  9. C#练习题答案: 巴路士惠勒改造【难度:4级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    巴路士惠勒改造[难度:4级]: 答案1: using System; using System.Collections.Generic; using System.Linq;public class ...

最新文章

  1. MySQL 8.0版本无法使用 node、Navicat等三方工具连接的问题
  2. android log4,GitHub - oronno/log4android: Log4Android - Simple Logging Wrapper Library for Android
  3. 数据结构与算法-- 二叉树中和为某一值的路径
  4. MS SQL 2000 分配权限
  5. 相信什么,生命就走向什么
  6. 稀缺生物科技美妆海报PSD分层模板,看得见的超前感!
  7. 牛客假日团队赛1 A.蹄球锦标赛
  8. 利用Python把遥感影像的某几个波段合成
  9. CSS实现tag标签挂载放到卡片上
  10. 清华源加速 添加在pip install xxx后面即可
  11. python局域网嗅探_Python_sniffer(网络嗅探器)
  12. mysql 同义词_在数据库mysql中存储和检索同义词的最佳方法
  13. buck斩波电路matlab,直流斩波电路的MATLAB建模与仿真.doc
  14. php 操作 PSD,PHP中怎么使用Imagick操作PSD文件
  15. php 计算今天周几,php如何计算当前日期是周几
  16. PAT 1124 Raffle for Weibo Followers python解法
  17. 紫装の槍使い(トゥーヴァ) / 紫枪(异时层土法)
  18. 回首2022,展望2023
  19. 基于springboot vue elementui酒店预订系统源码(毕设)
  20. CVPR2022论文集锦 | CVPR2022最新论文 | CVPR2022审稿结果 | CVPR2022录取结果

热门文章

  1. leetcode 1110. 删点成林
  2. courant数_柯朗数(Courant number)研究
  3. centos7 默认中文字体_如何更换CentOS(Linux)系统默认字体?
  4. LWN: STARTTLS 的坏处!
  5. win7账号切换计算机名,win7风林火山系统电脑如何修改系统账户名
  6. boost:timer,计时器
  7. mysql简易购物车系统_基于PHP+Mysql简单实现了图书购物车系统的实例详解
  8. 博图V16和人机界面仿真为啥不成功啊,哪位大哥麻烦看下
  9. 使用go语言编写一个播放器
  10. linux postgresql 做数据定时备份以及清理