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.IO;
- namespace hashmapapp
- {
- class Program
- {
- struct wordData
- {
- public int count;
- public List<int> stringsContaining;
- }
- static void Main(string[] args)
- {
- StreamReader reader = new StreamReader("input.txt");
- Dictionary<string, wordData> dict = new Dictionary<string, wordData>();
- int i = 0;
- string s;
- while (!reader.EndOfStream)
- {
- s = reader.ReadLine();
- string[] words = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (string word in words)
- {
- if (dict.ContainsKey(word))
- {
- wordData temp = dict[word];
- temp.count++;
- if (!temp.stringsContaining.Contains(i))
- {
- temp.stringsContaining.Add(i);
- }
- dict[word] = temp;
- }
- else
- {
- wordData temp = new wordData();
- temp.count = 1;
- temp.stringsContaining = new List<int>();
- temp.stringsContaining.Add(i);
- dict.Add(word, temp);
- }
- }
- i++;
- }
- foreach (KeyValuePair<string, wordData> k in dict)
- {
- Console.WriteLine(k.Key + " x " + k.Value.count);
- foreach (int l in k.Value.stringsContaining)
- {
- Console.WriteLine("In string #" + l);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement