Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- string candy;
- var stream = new FileStream(@"C:\Users\Mads\Documents\Candy.Txt",FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
- StreamReader reader = new StreamReader(stream);
- candy = reader.ReadToEnd();
- string[] lines = candy.Split(new string[] {Environment.NewLine}, StringSplitOptions.None);
- Dictionary<string,int> listofCandy = new Dictionary<string, int>();
- string currentItem = String.Empty;
- int count = 0;
- foreach (string s in lines)
- {
- if (listofCandy.ContainsKey(s))
- {
- listofCandy[s]++;
- }
- else
- {
- listofCandy.Add(s,1);
- }
- }
- double allcandy = 0;
- foreach (KeyValuePair<string, int> pair in listofCandy)
- {
- allcandy += pair.Value;
- }
- foreach (KeyValuePair<string, int> pair in listofCandy)
- {
- double percentage = pair.Value / allcandy;
- Console.WriteLine(pair.Key + " " + pair.Value + " " + percentage * 100 + "%");
- }
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement