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 ArrayHistogram
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] array = Console.ReadLine().Split(' ').ToArray();
- List<string> words = new List<string>();
- List<int> counts = new List<int>();
- for (int i = 0; i < array.Length; i++)
- {
- if (!words.Contains(array[i]))
- {
- words.Add(array[i]);
- counts.Add(1);
- }
- else
- {
- int index = words.IndexOf(array[i]);
- counts[index]++;
- }
- }
- for (int firstUnsorted = 0; firstUnsorted < counts.Count - 1; firstUnsorted++)
- {
- var i = firstUnsorted + 1;
- while (i > 0)
- {
- if (counts[i - 1] <counts[i])
- {
- int temp = counts[i];
- counts[i] = counts[i -1];
- counts[i -1] = temp;
- string tempWord = words[i];
- words[i] = words[i - 1];
- words[i - 1] = tempWord;
- }
- i--;
- }
- }
- for (int i = 0; i < words.Count; i++)
- {
- Console.WriteLine("{0} -> {1} times ({2:f2}%)", words[i], counts[i],
- ((double)counts[i] / (double) array.Length) *100);
- }
- }
- }
- }
- /*
- Dictionary<string, int> blah = new Dictionary<string, int>();
- foreach (string item in array)
- {
- if (item != "")
- {
- if (blah.ContainsKey(item) == false)
- {
- blah.Add(item, 1);
- }
- else
- {
- blah[item]++;
- }
- }
- }
- foreach (var item in blah)
- {
- Console.WriteLine(item);
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement