Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _07_Count_Numbers
- {
- class CountNumbers
- {
- static void Main(string[] args)
- {
- string inputStr = "8 2 2 8 2 2 3 7"; // For EXAMPLE only
- //string inputStr = Console.ReadLine();
- List<int> inputL = inputStr.Split().Select(int.Parse).ToList();
- List<int> tempL = inputL;
- int[] countNum = new int[inputL.Max()+1];
- int lenTemp;
- // Console.WriteLine("Input List --> "+string.Join(" ", inputL));
- foreach (var num in inputL)
- {
- lenTemp = tempL.Count;
- for (int j = 0; j < lenTemp; j++)
- {
- if (tempL[j] == num)
- {
- countNum[num]++;
- tempL.RemoveAt(j);
- lenTemp--;
- j--;
- }
- }
- } // End of Foreach
- for (int i = 0; i <= 1000; i++)
- {
- if (countNum[i]>0)
- {
- Console.WriteLine($"{i} -> {countNum[i]}");
- }
- }
- // Console.WriteLine("\n"+string.Join(" ",countNum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement