Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ What values have the greatest frequency? ♦
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav ➡ rextester.com/users/376 // in reply to MSDN thread: bit.ly/2iGdFNn namespace Rextester { public class Program { public static void Main(string[] args) { // what values have the greatest frequency in this array? int[] arr={ 11,12,123,-1,123,9,5,7,9,3, -1,8,123,7,9,5,-1,2,3,7, 1,9,-1,7,9,7,123,123,-1,-6, -99,-99,-99,-99,55,44,78,-99,-60,-60, }; arr .GroupBy(e=>e,(e,es)=>new/*y*/{Value=e,Frequency=es.Count()}) .GroupBy(y=>y.Frequency,(f,ys)=>new/*x*/{Frequency=f,Values=ys.ToList()}) .OrderByDescending(x=>x.Frequency) .First()/*first x from ordered xs*/ .Values/*property from first x*/ .ForEach/*value from List<y>*/(Console.WriteLine) ; Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
circular linked list
1
Non-User input - Random Controlled - Guessing Game
Range List for C#
Some linq examples
linear search
multiplo de 500
Numerical string to fancy graphical output
Random number between 1 - 100 between each value of 10 there will be a differnt message
Y Fibonnoci
Please log in to post a comment.