Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
count occurances
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //array = [1,4,2,5,4,2,5,1,6,2,5,3,8,9,6] //Write a program to count the occurrence of each distinct item in the array? //Builin array functions and LINQ are not allowed. int[] intputArray = {1,4,2,5,4,2,5,1,6,2,5,3,8,9,6}; Dictionary<int,int> trackCount = new Dictionary<int,int>(); for(int i=0;i <intputArray.Length;i++) { if(trackCount.ContainsKey(intputArray[i])) { trackCount[intputArray[i]]= trackCount[intputArray[i]]+1; } else { trackCount.Add(intputArray[i],1); } } foreach(var item in trackCount) { Console.WriteLine(item.Key + " "+item.Value); } } } }
run
|
edit
|
history
|
help
0
/Users/svetlanakanevskaa/Downloads/ACDB.sql
THRWSC SDXS
project euler 17, C#
sdfrgthyjukiujyht5r4der
עעעע
Fórum ➡ Parallel Threads ( The Funniest Version ) ♦
Simple Constructor Implementation
abdurrahimcan@gmail.com
retrylogic
Armstrong