Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sing System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _04ArrayAndListsExcercisesArrayHistogram
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> words = new List<string>();
- List<string> inputString = Console.ReadLine().Split(' ').ToList();
- List<int> counts = new List<int>();
- for (int i = 0; i < inputString.Count; i++)
- {
- if(!words.Contains(inputString[i]))
- {
- words.Add(inputString[i]);
- counts.Add(1);
- }
- else
- {
- int index = words.IndexOf(inputString[i]);
- counts[index]++;
- }
- }
- for (int i = 0; i < counts.Count - 1; i++)
- {
- int index = i + 1;
- while (index > 0)
- {
- if (counts[index - 1] < counts[index])
- {
- int tempCount = counts[index];
- counts[index] = counts[index - 1];
- counts[index - 1] = tempCount;
- string wordCount = words[index];
- words[index] = words[index - 1];
- words[index - 1] = wordCount;
- }
- index--;
- }
- }
- for (int i = 0; i < words.Count; i++)
- {
- Console.WriteLine("{0} -> {1} times ({2:f2}%)", words[i], counts[i], (((double)counts[i] / (double)inputString.Count) * 100));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment