static void Main() { string input = Console.ReadLine(); List<decimal> inputNums = new List<decimal>(); List<decimal> oddNums = new List<decimal>(); List<decimal> evenNums = new List<decimal>(); string[] numbers = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var num in numbers) { inputNums.Add(decimal.Parse(num)); } int index = 1; for (int i = 0; i < inputNums.Count; i++) { if (index % 2 == 1) { oddNums.Add(inputNums[i]); } else { evenNums.Add(inputNums[i]); } index++; } if (inputNums.Count == 0) { Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No"); } else if (inputNums.Count == 1) { double oddNumsSum = (double)oddNums.Sum(); double oddNumsMin = (double)oddNums.Min(); double oddNumsMax = (double)oddNums.Max(); Console.WriteLine("OddSum={0:G0}, OddMin={1:G0}, OddMax={2:G0}, EvenSum=No, EvenMin=No, EvenMax=No", oddNumsSum, oddNumsMin, oddNumsMax); } else { double oddNumsSum = (double)oddNums.Sum(); double oddNumsMin = (double)oddNums.Min(); double oddNumsMax = (double)oddNums.Max(); double evenNumsSum = (double)evenNums.Sum(); double evenNumsMin = (double)evenNums.Min(); double evenNumsMax = (double)evenNums.Max(); Console.WriteLine("OddSum={0:G0}, OddMin={1:G0}, OddMax={2:G0}, EvenSum={3:G0}, EvenMin={4:G0}, EvenMax={5:G0}", // {...:G0} Remove trailing zeros oddNumsSum, oddNumsMin, oddNumsMax, evenNumsSum, evenNumsMin, evenNumsMax); } }
private void ShowSampleItems_Click(object sender, EventArgs e) { // create some sample items; MyMap.MapElements.Clear(); MyMap.Layers.Clear(); var bounds = new List<LocationRectangle>(); foreach (var area in DataManager.SampleAreas) { var shape = new MapPolygon(); foreach (var parts in area.Split(' ').Select(cord => cord.Split(','))) { shape.Path.Add(new GeoCoordinate(double.Parse(parts[1], ci), double.Parse(parts[0], ci))); } shape.StrokeThickness = 3; shape.StrokeColor = Colors.Blue; shape.FillColor = Color.FromArgb((byte)0x20, shape.StrokeColor.R, shape.StrokeColor.G, shape.StrokeColor.B); bounds.Add(LocationRectangle.CreateBoundingRectangle(shape.Path)); MyMap.MapElements.Add(shape); } var rect = new LocationRectangle(bounds.Max(b => b.North), bounds.Min(b => b.West), bounds.Min(b => b.South), bounds.Max(b => b.East)); MyMap.SetView(rect); // show all Items var itemsLayer = new MapLayer(); foreach (var item in DataManager.SampleItems) { DrawItem(item, "Ulm", itemsLayer); } MyMap.Layers.Add(itemsLayer); }
public static Tuple<int, int> getSmartPosition(List<System.Drawing.Rectangle> listRect, System.Drawing.Rectangle rect) { HashSet<Rectangle> hsRect = new HashSet<Rectangle>(listRect); List<Rectangle> listGotCollide = new List<Rectangle>(); foreach (var item in hsRect) { Rectangle intersect = Rectangle.Intersect(item, rect); if (intersect.Width > 1 && intersect.Height > 1) { listGotCollide.Add(item); } } int xOuter = listGotCollide.Min(item => item.X); int yOuter = listGotCollide.Min(item => item.Y); int xInner = xOuter + 32; int yInner = yOuter + 32; int xResult = Math.Abs(rect.X - xOuter) > Math.Abs(rect.X - xInner) ? xInner : xOuter; int yResult = Math.Abs(rect.Y - yOuter) > Math.Abs(rect.Y - yInner) ? yInner : yOuter; Tuple<int, int> result = new Tuple<int, int>(xResult, yResult); return result; }
public ShipOnMap(Texture2D texture, Texture2D circle, Vector2 position, Vector2 scale, List<Ship> ships) { Texture = texture; Circle = circle; Scale = scale; this.position = position; this.velocity = ships.Min(x => x.Velocity); FinalWidth = position.X + texture.Width * scale.X; FinalHeight = position.Y + texture.Height * scale.Y; Ships = ships; IsPressed = false; IsOwnByThisPlayer = false; IsRightButtonPressed = false; IsMoving = false; SpeedMod = ships.Min(x => x.SpeedMod); Origin = new Vector2(Texture.Width / 2, Texture.Height / 2); CircleOrigin = new Vector2((Circle.Width - Texture.Width) / 2, (Circle.Height - Texture.Height) / 2); CircleScale = Scale; Rotation = 0; Timer = 0; Mobility = 0; Target = null; IsMovingToSystem = false; IsVisible = true; }
static void Main() { var numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; var odd = numbers.WhereNot(x => x % 2 == 0); Console.WriteLine(string.Join(" ", odd)); var numbersBiggerThanTen = numbers.WhereNot(LessThanTen); Console.WriteLine(string.Join(" ", numbersBiggerThanTen)); Console.WriteLine(); var students = new List<Student>() { new Student("Stavri",5.5), new Student("Loshiq",2), new Student("Me4a", 3.50), new Student("Anatoli", 4.4), new Student("Rambo", 5.95) }; Console.WriteLine(students.Max(student => student.Grade)); Console.WriteLine(students.Min(Grade)); Console.WriteLine(); Console.WriteLine(students.Max(Name)); Console.WriteLine(students.Min(student => student.Name)); }
private static Map ParseMap(string zone, string[] lines) { Map tmpMap = new Map(); tmpMap.zone = zone; if (tmpMap.zone != "") { List<MapLineSegment> segmentList = new List<MapLineSegment>(); foreach (string l in lines) { if (l[0] == 'L') { segmentList.Add(ParseSegment(l)); } else if (l[0] == 'P') { //parse place } } //group up line segments according to color(RGB) value, then create one pen for each color used //this should greatly lower the overhead for creating brush and pen objects //*edit* aparently not. List<MapLineSegment> distinctSegments = segmentList.Distinct(new MapLineSegmentColorComparer()).ToList(); foreach (MapLineSegment colorSource in distinctSegments) { List<MapLineSegment> tmpSegmentList = segmentList.FindAll(x => x.color == colorSource.color); SolidColorBrush colorBrush = new SolidColorBrush(colorSource.color); Pen tmpPen = new Pen(colorBrush, 1.0); tmpMap.lineList.Add(new MapLine(tmpSegmentList, tmpPen)); } if (segmentList.Count > 0) { tmpMap.maxX = Math.Max(segmentList.Max(x => x.aX), segmentList.Max(x => x.bX)); tmpMap.maxY = Math.Max(segmentList.Max(x => x.aY), segmentList.Max(x => x.bY)); tmpMap.minX = Math.Min(segmentList.Min(x => x.aX), segmentList.Min(x => x.bX)); tmpMap.minY = Math.Min(segmentList.Min(x => x.aY), segmentList.Min(x => x.bY)); tmpMap.width = tmpMap.maxX - tmpMap.minX; tmpMap.height = tmpMap.maxY - tmpMap.minY; tmpMap.depth = tmpMap.maxZ - tmpMap.minZ; } } return tmpMap; }
private void AddPlotSeries(List<Tuple<double, double>> ansv, double stepX, double stepY) { _stepX = stepX; _stepY = stepY; if (!_firstLoaded) DrawGrid(ansv.Min(item => item.Item1), ansv.Max(item => item.Item1), stepX, ansv.Min(item => item.Item2), ansv.Max(item => item.Item2), stepY); MyCanvas.Children.Add(GenerateSeriesPath(ansv)); }
/// <summary> /// /// </summary> /// <param name="table"></param> /// <param name="chart"></param> /// <param name="indexAxisX"></param> /// <param name="indexAxisY"></param> public void Plot(DataTable table, Chart chart, int indexAxisX, int indexAxisY) { if (HasNull(table)) { MessageBox.Show(@"Iterate data first!"); } else { try { var xValue = new List<double>(); var yValue = new List<double>(); foreach (var series in chart.Series) { series.Points.Clear(); } for (var i = 1; i < table.Columns.Count; i++) { xValue.Add( Convert.ToDouble(table.Rows[indexAxisX][i].ToString())); yValue.Add( Convert.ToDouble(table.Rows[indexAxisY][i].ToString())); } if (Math.Abs(xValue.Min() - xValue.Max()) < 0.0000001 || Math.Abs(yValue.Min() - yValue.Max()) < 0.0000001) { MessageBox.Show(@"The selected data cannot be charted!"); } else { chart.Series[0].Points.DataBindXY(xValue, yValue); chart.Series[0].ChartType = SeriesChartType.FastLine; chart.Series[0].Color = Color.Black; chart.ChartAreas[0].AxisX.Maximum = xValue.Max(); chart.ChartAreas[0].AxisX.Minimum = xValue.Min(); chart.ChartAreas[0].AxisY.Maximum = yValue.Max(); chart.ChartAreas[0].AxisY.Minimum = yValue.Min(); chart.ChartAreas[0].AxisX.MajorGrid.Enabled = true; chart.ChartAreas[0].AxisY.MajorGrid.Enabled = true; chart.ChartAreas[0].AxisX.Title = table.Rows[indexAxisX][0].ToString(); chart.ChartAreas[0].AxisY.Title = table.Rows[indexAxisY][0].ToString(); chart.Series[0].IsVisibleInLegend = false; } } catch (Exception ex) { MessageBox.Show(@"Chart error: " + ex.Message); } } }
static void Main() { string numbersString = Console.ReadLine(); if (numbersString == "") { Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No"); } else { decimal[] numbers = Array.ConvertAll(numbersString.Split(' '), decimal.Parse); List<decimal> odd = new List<decimal>(); List<decimal> even = new List<decimal>(); for (int i = 0; i < numbers.Length; i++) { if (i % 2 == 0) { odd.Add(numbers[i]); } else { even.Add(numbers[i]); } } if ((odd.Count == 0 && even.Count == 0) || numbersString == "") { Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No"); } if (even.Count == 0) { decimal oddSum = odd.Sum(); decimal oddMin = odd.Min(); decimal oddMax = odd.Max(); Console.WriteLine("OddSum={0:0.##}, OddMin={1:0.##}, OddMax={2:0.##}, EvenSum=No, EvenMin=No, EvenMax=No", oddSum, oddMin, oddMax); } else { decimal oddSum = odd.Sum(); decimal oddMin = odd.Min(); decimal oddMax = odd.Max(); decimal evenSum = even.Sum(); decimal evenMin = even.Min(); decimal evenMax = even.Max(); Console.WriteLine("OddSum={0:0.##}, OddMin={1:0.##}, OddMax={2:0.##}, EvenSum={3:0.##}, EvenMin={4:0.##}, EvenMax={5:0.##}" , oddSum, oddMin, oddMax, evenSum, evenMin, evenMax); } } }
public static Point MinPoint( List<Point> points, Axis axis) { double min; if (axis == Axis.X) { min = points.Min(p => p.X); return points.FirstOrDefault(p => DoubleCompare(p.X , min)); } min = points.Min(p => p.Y); return points.FirstOrDefault(p => DoubleCompare(p.Y, min)); }
public VectorPath(List<VectorPathSegment> seg) { segments = seg; Length = segments.Sum(p => p.Length); float top = segments.Min(p => p.Boundings.Top); float bot = segments.Max(p => p.Boundings.Bottom); float lef = segments.Min(p => p.Boundings.Left); float rig = segments.Max(p => p.Boundings.Right); Boundings = new FRectangle(lef, top, rig-lef, bot-top); }
public Rectangle boundingRectangle(List<Point> points) { // Add checks here, if necessary, to make sure that points is not null, // and that it contains at least one (or perhaps two?) elements var minX = points.Min(p => p.X); var minY = points.Min(p => p.Y); var maxX = points.Max(p => p.X); var maxY = points.Max(p => p.Y); return new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY)); }
public static void GetEnvelope(double lat, double lon, double dist, out double minLat, out double minLon, out double maxLat, out double maxLon) { var gc = new GeodeticCalculator(); var endpoints = new List<GlobalCoordinates>(); endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(0), dist * 1000.0)); endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(90), dist * 1000.0)); endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(180), dist * 1000.0)); endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(270), dist * 1000.0)); minLat = endpoints.Min(x => x.Latitude.Degrees); maxLat = endpoints.Max(x => x.Latitude.Degrees); minLon = endpoints.Min(x => x.Longitude.Degrees); maxLon = endpoints.Max(x => x.Longitude.Degrees); }
public static void Sorting(List<int> array) { int[] sortedArray = new int[array.Count]; for (int i = 0; i < sortedArray.Length; i++) { sortedArray[i] = array.Min(); array.Remove(array.Min()); } Console.WriteLine("The sorted array is: "); for (int i = 0; i < sortedArray.Length; i++) { Console.WriteLine(sortedArray[i]); } }
private void AssignLabel() { Doggies.ForEach(x => { var distances = new List<double> () { GetEuclideanDistance(x, chihuahuaCentroid), GetEuclideanDistance(x, beaglesCentroid), GetEuclideanDistance(x, daschundCentroid) }; if (distances[0] == distances.Min()) x.Label = Label.Chihuahuas; else if (distances[1] == distances.Min()) x.Label = Label.Beagles; else x.Label = Label.Daschunds; FixCentroids(x.Label); }); }
static void Main(string[] args) { int[] numbers = Console .ReadLine() .Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(item => int.Parse(item)) .ToArray(); List<int> allNumbers = new List<int>(); List<int> sortNumbers = new List<int>(); for (int i = 0; i < numbers.Length; i++) { allNumbers.Add(numbers[i]); } for (int i = 0; i < numbers.Length; i++) { for (int j = 0; j < allNumbers.Count; j++) { int min = allNumbers.Min(); allNumbers.Remove(min); sortNumbers.Add(min); } } Console.Write(string.Join(" ", sortNumbers)); Console.WriteLine(); }
static void Main(string[] args) { string[] input = Console.ReadLine().Split(); float[] array = Array.ConvertAll(input, float.Parse); List<float> roundNumbers = new List<float>(); List<float> floatingPointNumbers = new List<float>(); for (int i = 0; i < array.Length; i++) { if (array[i] % 1 == 0) { roundNumbers.Add(array[i]); } else { floatingPointNumbers.Add(array[i]); } } Console.WriteLine("[" + string.Join(" ,", floatingPointNumbers) + "]" + " -> min: {0}, max:{1}, sum:{2}, avg:{3}", floatingPointNumbers.Min(), floatingPointNumbers.Max(), floatingPointNumbers.Sum(), String.Format("{0:0.00}", floatingPointNumbers.Average())); Console.WriteLine("[" + string.Join(" ,", roundNumbers) + "]" + " -> min: {0}, max:{1}, sum:{2}, avg:{3}", roundNumbers.Min(), roundNumbers.Max(), roundNumbers.Sum(), String.Format("{0:0.00}", roundNumbers.Average())); }
static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; float[] allNumbers = Console.ReadLine().Split(' ').Select(float.Parse).ToArray(); List<float> fpNumbers = new List<float> { }; List<int> integerNumbers = new List<int> { }; for (int index = 0; index < allNumbers.Length; index++) { if (allNumbers[index].ToString().Contains('.')) { fpNumbers.Add(allNumbers[index]); } else { integerNumbers.Add((int)allNumbers[index]); } } Console.WriteLine("[{0}] -> min: {1}, max: {2}, sum: {3}, avg: {4:f2}" , string.Join(", ", fpNumbers) , fpNumbers.Min() , fpNumbers.Max() , fpNumbers.Sum() , fpNumbers.Average()); Console.WriteLine("[{0}] -> min: {1}, max: {2}, sum: {3}, avg: {4:f2}" , string.Join(", ", integerNumbers) , integerNumbers.Min() , integerNumbers.Max() , integerNumbers.Sum() , integerNumbers.Average()); }
public double CariDiApple(double imApple1,double imApple2,double imApple3,double imApple4,double imApple5,double imApple6,double imApple7) { List<double> listUApple = new List<double>(); SqlConnection sqlcon = new SqlConnection(con); sql = "select * from Apple"; sqlcon.Open(); SqlCommand cmd = new SqlCommand(sql, sqlcon); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { double h1 = Math.Abs(Convert.ToDouble(dr["m1"]) - imApple1); double h2 = Math.Abs(Convert.ToDouble(dr["m2"]) - imApple2); double h3 = Math.Abs(Convert.ToDouble(dr["m3"]) - imApple3); double h4 = Math.Abs(Convert.ToDouble(dr["m4"]) - imApple4); double h5 = Math.Abs(Convert.ToDouble(dr["m5"]) - imApple5); double h6 = Math.Abs(Convert.ToDouble(dr["m6"]) - imApple6); double h7 = Math.Abs(Convert.ToDouble(dr["m7"]) - imApple7); double Nh = Math.Sqrt(Math.Pow(h1,2)+Math.Pow(h2,2)+Math.Pow(h3,2)+Math.Pow(h4,2)+Math.Pow(h5,2)+Math.Pow(h6,2)+Math.Pow(h7,2)); listUApple.Add(Nh); } sqlcon.Close(); NApple = listUApple.Min(); return NApple; }
public ActionResult Index(int id, List<int> grSel) { var db = new ZkDataContext(); var post = db.ForumPosts.Find(id); string txt1; string txt2; if (grSel != null && grSel.Any()) { if (grSel.Count > 1) { txt1 = db.ForumPostEdits.Find(grSel.Min()).NewText; txt2 = db.ForumPostEdits.Find(grSel.Max()).NewText; } else { var edit = db.ForumPostEdits.Find(grSel.First()); txt1 = edit.OriginalText; txt2 = edit.NewText; } var sd = new SideBySideDiffBuilder(new Differ()); ViewBag.DiffModel = sd.BuildDiffModel(txt1, txt2); } else { var edit = post.ForumPostEdits.OrderByDescending(x => x.ForumPostEditID).FirstOrDefault(); if (edit != null) { var sd = new SideBySideDiffBuilder(new Differ()); ViewBag.DiffModel = sd.BuildDiffModel(edit.OriginalText, edit.NewText); } } return View("PostHistoryIndex", post); }
static void Main(string[] args) { string[] numbers = Console.ReadLine().Split(' '); List<double> floatingNumbers = new List<double>(); List<int> integerNumbers = new List<int>(); foreach(string number in numbers) { if (number.Contains(".")) { double number2 = double.Parse(number); if (number2 % 1 == 0) { integerNumbers.Add(Convert.ToInt32(number2)); } else { floatingNumbers.Add(number2); } } else { integerNumbers.Add(int.Parse(number)); } } string output = string.Join(", ", floatingNumbers); Console.WriteLine("{0} -> min: {1:f2}, max: {2:f2}, sum: {3:f2}, avg: {4:f2}", output, floatingNumbers.Min(), floatingNumbers.Max(), floatingNumbers.Sum(), floatingNumbers.Average()); output = string.Join(", ", integerNumbers); Console.WriteLine("{0} -> min: {1}, max: {2}, sum: {3}, avg: {4:f2}", output, integerNumbers.Min(), integerNumbers.Max(), integerNumbers.Sum(), integerNumbers.Average()); }
public override double GetNominalStrength() { //(17.4.1.2) List<double> stresses = new List<double>() { 125000, 1.9 * fya, futa }; double N_sa = n * (A_se_N * stresses.Min() / 1000); return N_sa; }
private void FindPath(int startNode) { List<int> unprocessedNodesIdxs = new List<int>(); foreach(var n in _Graph.Keys) { _ClosestNodes[n] = new Edge { Distance = decimal.MaxValue }; unprocessedNodesIdxs.Add(n); } _ClosestNodes[startNode].Distance = 0; while(unprocessedNodesIdxs.Count > 0) { var currentNodeIdx = unprocessedNodesIdxs.First(p => _ClosestNodes[p].Distance == unprocessedNodesIdxs.Min(pp => _ClosestNodes[pp].Distance)); unprocessedNodesIdxs.Remove(currentNodeIdx); foreach(var outEdge in _Graph[currentNodeIdx]) { decimal currentDistance = _ClosestNodes[outEdge.NextNodeId].Distance; decimal newDistance = Math.Min(currentDistance, _ClosestNodes[currentNodeIdx].Distance + outEdge.EdgeVeight); if(newDistance < currentDistance) { _ClosestNodes[outEdge.NextNodeId].Distance = newDistance; _ClosestNodes[outEdge.NextNodeId].NextNodeId = currentNodeIdx; } } } }
static void Main() { Console.Write("Please enter a positive integer number: "); int n = int.Parse(Console.ReadLine()); var temp = new List<decimal>(); decimal add = 0; if (n != 1) { for (int i = 1; i <= n; i++) { Console.Write("Please enter number {0}: ", i); add = decimal.Parse(Console.ReadLine()); temp.Add(add); } } decimal sum = temp.Sum(); decimal min = temp.Min(); decimal max = temp.Max(); decimal avg = sum / n; Console.WriteLine("------------------------", min, max, sum, avg); Console.WriteLine("min = {0:F0}\n\rmax = {1:F0}\n\rsum = {2:F0}\n\ravg = {3:F2}", min, max, sum, avg); Console.ReadKey(); }
public async Task RunAsync(CancellationToken cancellationToken) { var sw = Stopwatch.StartNew(); var min = _fromDate.ToUniversalTime().Ticks; var max = _toDate.ToUniversalTime().Ticks; var table = _tableClient.GetTableReference("WADPerformanceCountersTable"); var query = new TableQuery<WADPerformanceCountersTable>() .Where(TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, min.ToString("d19")), TableOperators.And, TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThan, max.ToString("d19")))); var result = new List<WADPerformanceCountersTable>(); TableContinuationToken token = null; do { var segment = await table.ExecuteQuerySegmentedAsync(query, token, null, null, cancellationToken); token = segment.ContinuationToken; result.AddRange(segment.Results); // Console.Write($"{segment.Results.Count}."); } while (token != null); Console.WriteLine(); sw.Stop(); Console.WriteLine("Count:{0}, Min: {1}, Max: {2}, Elapsed: {3:F2} sec", result.Count, result.Min(e => e.PartitionKey), result.Max(e => e.PartitionKey), (sw.ElapsedMilliseconds / 1000.0)); }
public Histogram(List<uint> items, int binsArg) { TotalBins = binsArg; // Performs binning. Reference: http://stackoverflow.com/questions/2387916/looking-for-a-histogram-binning-algorithm-for-decimal-data Min = items.Min(); Max = items.Max(); bins = new List<uint>(TotalBins); for (int i = 0; i < TotalBins; i++) { bins.Add(0); } BinSize = (Max - Min) / (uint)TotalBins; foreach (var value in items) { int bucketIndex = 0; if (BinSize > 0.0) { bucketIndex = (int)((value - Min) / BinSize); if (bucketIndex >= TotalBins) { bucketIndex = TotalBins - 1; } } bins[bucketIndex]++; } }
static void Main(string[] args) { List<string> elements = Console.ReadLine().Split(' ').ToList(); List<int>integers=new List<int>(); List<double> decimals = new List<double>(); foreach (var item in elements) { if((double.Parse(item)-Math.Ceiling(double.Parse(item)))==0) integers.Add(Convert.ToInt32(Math.Ceiling(double.Parse(item)))); else decimals.Add(double.Parse(item)); } Console.Write("[ "); integers.ForEach(i => Console.Write("{0} ", i)); Console.Write("]"); double min=integers.Min(); double max=integers.Max(); double sum=integers.Sum(); double avg=integers.Average(); Console.WriteLine(" -> min: {0}, max: {1}, sum: {2}, avg: {3:0.00}",min,max,sum,avg); Console.WriteLine(); Console.Write("[ "); decimals.ForEach(j => Console.Write("{0} ", j)); Console.Write("]"); min = decimals.Min(); max = decimals.Max(); sum = decimals.Sum(); avg = decimals.Average(); Console.WriteLine(" -> min: {0}, max: {1}, sum: {2}, avg: {3:0.00}", min, max, sum, avg); Console.WriteLine(); }
public GiftBox CreateBox(List<string> dimensions) { if (dimensions.Count != 3) { throw new InvalidOperationException("Box was malformed in number of dimensions: " + dimensions.Count); } if (0 == dimensions.Min(x => x.Length)) { throw new InvalidOperationException("Box was malformed"); } int length; int width; int height; if (!int.TryParse(dimensions[0], out length)) { throw new InvalidOperationException("Failed to parse length: " + dimensions[0]); } if (!int.TryParse(dimensions[1], out width)) { throw new InvalidOperationException("Failed to parse width: " + dimensions[1]); } if (!int.TryParse(dimensions[2], out height)) { throw new InvalidOperationException("Failed to parse height: " + dimensions[2]); } return new GiftBox(length, width, height); }
public bool Graph(bool genCustom = true) { var logN = new LogNormal(); var normal = new Normal(); var m = genCustom ? normal.GenCustomNormal(1000000, Environment.TickCount) : normal.GenNormal(10000); var mas = new double[m.Count]; var i = 0; var list = new List<double>(); foreach (var el in m) { list.Add(el); mas[i] = logN.GenLogNormalNumber(1, 10, el); i++; } var res = new CreateGraphicData(); res.Create(mas, 80); var gg = new GetMuSigma(list.ToArray()); Console.WriteLine(gg.ResultMu + "\n" + gg.ResultSigma); Console.WriteLine(list.Min()); Console.ReadLine(); return true; }
static void Main() { string input = Console.ReadLine(); double[] numbers = input.Split().Select(double.Parse).ToArray(); List<double> roundNum = new List<double>(); List<double> zeroFractNum = new List<double>(); for (int i = 0; i < numbers.Length; i++) { if (numbers[i] % 1 != 0) { zeroFractNum.Add(numbers[i]); } else { roundNum.Add(numbers[i]); } } Console.WriteLine("Zero Fractional Numbers"); zeroFractNum.ForEach(a => Console.WriteLine(a + " ")); Console.WriteLine("max = {0}", zeroFractNum.Max()); Console.WriteLine("min = {0}", zeroFractNum.Min()); Console.WriteLine("sum = {0}", zeroFractNum.Sum()); Console.WriteLine("avg = {0}", zeroFractNum.Average()); Console.WriteLine("Round Numbers"); roundNum.ForEach(a => Console.WriteLine(a + " ")); Console.WriteLine("max = {0}", roundNum.Max()); Console.WriteLine("sum = {0}", roundNum.Sum()); Console.WriteLine("min = {0}", roundNum.Min()); Console.WriteLine("avg = {0}", roundNum.Average()); }