C#练习题答案: 寻找恩人【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
寻找恩人【难度:1级】:
答案1:
using System;
using System.Linq;public class NewAverage
{public static long NewAvg(double[] arr, double navg){var donation = (arr.Length + 1) * navg - arr.Sum();if (donation <= 0){throw new ArgumentException();}return (long)Math.Ceiling(donation);}
}
答案2:
using System;
using System.Linq;public class NewAverage
{public static long NewAvg(double[] arr, double navg){double nextDonation = Math.Ceiling(navg * (arr.Length + 1) - arr.Sum());if(nextDonation <= 0) throw new ArgumentException();return Convert.ToInt32(nextDonation);}
}
答案3:
using System;
using System.Linq;public class NewAverage
{public static long NewAvg(double[] arr, double navg){double add = (arr.Length + 1) * navg - arr.Sum();if (add <= 0)throw new ArgumentException("Expected New Average is too low", ""); return (long)Math.Ceiling(add);}
}
答案4:
using System;
using System.Linq;public class NewAverage
{public static long NewAvg(double[] arr, double navg){long result = (long)Math.Ceiling(navg * (arr.Length + 1) - arr.Sum());if(result > 0) return result;throw new ArgumentException();}
}
答案5:
using System;using System.Linq;public class NewAverage{public static long NewAvg(double[] arr, double navg){if (arr.Sum() / (arr.Count() + 1) < navg)return (long) Math.Ceiling((navg - arr.Sum()/(arr.Count()+1))*(arr.Count() + 1));throw new ArgumentException();}}
答案6:
using System;
using System.Linq;public class NewAverage
{public static long NewAvg(double[] arr, double navg){if (arr.Length < 1){return (long)navg;}long result = (long)(Math.Ceiling((navg * (arr.Length + 1)) - arr.Sum()));return result > 0 ? result : throw new ArgumentException();}
}
答案7:
using System;
using System.Linq;
public class NewAverage
{public static long NewAvg(double[] arr, double navg){return (long)(navg * (arr.Count() + 1) - arr.Sum()) > 0 ? (long)Math.Ceiling(((navg * (arr.Count() + 1)) - arr.Sum())) :throw new ArgumentException();}
}
答案8:
using System.Linq;
using System;public class NewAverage
{public static long NewAvg(double[] arr, double navg){var donation = (arr.Length + 1) * navg - arr.Sum();if (donation <= 0){throw new ArgumentException();}return (long)Math.Ceiling(donation);}
}
答案9:
using System.Linq;
using System;
public class NewAverage
{public static long NewAvg(double[] arr, double navg){var result = Math.Ceiling((arr.Count() + 1) * navg - arr.Sum(x => x));if (result < 0 || navg < 0) throw new ArgumentException();return (long)result;}
}
答案10:
using System;
using System.Linq;public class NewAverage
{public static long NewAvg(double[] arr, double navg){var len = arr.Length + 1;var tot = arr.Sum();var ret = Convert.ToInt64(Math.Ceiling((navg * len) - tot));if (ret < 0) throw new ArgumentException();return ret;}
}
C#练习题答案: 寻找恩人【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战相关推荐
- C#练习题答案: 字母战争 - 核打击【难度:3级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
字母战争 - 核打击[难度:3级]: 答案1: using System; using System.Text.RegularExpressions; using System.Linq; publi ...
- C#练习题答案: 反恐精英系列【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
反恐精英系列[难度:1级]: 答案1: namespace CS {using System;using System.Collections.Generic;public class Kata{pr ...
- C#练习题答案: 图片#1 - 重建巴别塔【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
图片#1 - 重建巴别塔[难度:1级]: 答案1: using System.Linq;public static class Kata {public static string Babel(int ...
- 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 ...
- C#练习题答案: 英雄的根【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
英雄的根[难度:1级]: 答案1: using System;public class IntSqRoot {const int error = 1;public static long IntRac ...
- C#练习题答案: scytale的编码器/解码器(古斯巴达密码)【难度:3级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
scytale的编码器/解码器(古斯巴达密码)[难度:3级]: 答案1: using System; using System.Linq; using System.Text.RegularExpre ...
- C#练习题答案: 产品和LCMS之间的差异总和【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
产品和LCMS之间的差异总和[难度:1级]: 答案1: using System.Linq;public class Kata {static int gcd(int a, int b) {if(a ...
- C#练习题答案: 巴路士惠勒改造【难度:4级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
巴路士惠勒改造[难度:4级]: 答案1: using System; using System.Collections.Generic; using System.Linq;public class ...
- C#练习题答案: 折叠用自己的方式去月球【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
折叠用自己的方式去月球[难度:1级]: 答案1: using System; using System.Collections.Generic;public class Kata {public st ...
最新文章
- CUDA 并行计算优化策略总结
- Symantec(VeriSign)SSL证书
- linux history 命令 shell历史记录显示 HISTSIZE
- php复制mysql文件路径_与php 有关的问题 如何将上传的文件路径 保存到数据库中...
- MyBatisPlus3.x中使用代码生成器(全注释)
- c#中实现图像图像卷积与滤波-高斯平滑
- Redis的内部运作机制——Redis详解
- 18年韩师插本c语言的题答案,插本全能题库
- windows传文件给linux工具
- 是否还为制作PPT而烦恼?珍藏的PPT实用网站打包送给你!
- 如何把pdf拆分成多个文件?
- 北京师范大学计算机学院 姚力,姚力(北京师范大学信息科学与技术学院院长)_百度百科...
- 如何切换Echarts主题
- 深信服应用交付(AD)学习笔记
- PhxRPC源码简析
- vb.net 实现图片圆形渐变模糊
- Redis主从搭建(哨兵模式),springboot整合redis主从
- Matlab:合并来自各自变量的日期和时间
- 面向最大使用效益的充电站网络优化方法
- Oracle Primavera P6系列