Advertisement
Guest User

Ergo fuck

a guest
Nov 1st, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. string candy;
  6. var stream = new FileStream(@"C:\Users\Mads\Documents\Candy.Txt",FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
  7. StreamReader reader = new StreamReader(stream);
  8. candy = reader.ReadToEnd();
  9. string[] lines = candy.Split(new string[] {Environment.NewLine}, StringSplitOptions.None);
  10. Dictionary<string,int> listofCandy = new Dictionary<string, int>();
  11.  
  12. string currentItem = String.Empty;
  13. int count = 0;
  14.  
  15. foreach (string s in lines)
  16. {
  17. if (listofCandy.ContainsKey(s))
  18. {
  19. listofCandy[s]++;
  20. }
  21. else
  22. {
  23. listofCandy.Add(s,1);
  24. }
  25. }
  26. double allcandy = 0;
  27. foreach (KeyValuePair<string, int> pair in listofCandy)
  28. {
  29. allcandy += pair.Value;
  30. }
  31. foreach (KeyValuePair<string, int> pair in listofCandy)
  32. {
  33. double percentage = pair.Value / allcandy;
  34. Console.WriteLine(pair.Key + " " + pair.Value + " " + percentage * 100 + "%");
  35. }
  36.  
  37. Console.ReadKey();
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement